Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > making courser jump to text field on page load

making courser jump to text field on page load
Thread Tools
Forum Regular
Join Date: Jun 2003
Status: Offline
Reply With Quote
Mar 10, 2004, 12:23 PM
 
I am making a page with text box fields, and I would like to have courser jump to the first text box when the page loads. I searched for a javascript, but I didn't find one.

Does anyone know how to do this?
     
Grizzled Veteran
Join Date: Nov 2003
Location: Hebburn, UK
Status: Offline
Reply With Quote
Mar 10, 2004, 01:36 PM
 
Code:
document.getElementById("inputsID").focus()
should do the trick. I'm not sure if it's setFocus() for MSIE...

There's other ways of referencing the element (text box) too, like

Code:
document.getElementsByTagName("input")[0].focus()
so it's up to you...
Just who are Britain? What do they? Who is them? And why?

Formerly Black Book
     
Senior User
Join Date: Dec 2002
Status: Offline
Reply With Quote
Mar 10, 2004, 07:49 PM
 
I hate sites that do that, because I can usually type what I need in the first field before the page even loads completely (even though I'm on a 1.5Mbps connection) and I start typing the next field, the javascript selects the first field, and I lose what I typed! So annoying, don't do it!
Travis Sanderson
     
Grizzled Veteran
Join Date: Sep 2000
Location: New Jersey, USA
Status: Offline
Reply With Quote
Mar 12, 2004, 05:44 PM
 
I understood it as the actual mouse cursor jumping to the text field. Physical location of pointer on the display. The other posts seem to describe the selected text field. I do not know how to attempt the cursor itself but just thought I'd mention it.

Otherwise the original question seemed to miscommunicate the actual intent.
Dual 2.0 G5/2.5GB/ATI 9800 Pro | MacBook Pro 2.16 Gore Duo/2GB/ATI X1600
     
Grizzled Veteran
Join Date: Oct 2003
Status: Offline
Reply With Quote
Mar 12, 2004, 07:10 PM
 
I have seen a few pages do this without javascript. It is weird, but if there is an input box positioned correctly, alot of browsers seem to automatically select it. I'm not sure exactly what is happening on those pages, but I've come across a few pages in the past that did this, and when I checked source, there was no javascript or anything else I could find that would be making this happen. And almost all browsers I tried it in did it. Weird.

But if you want to do it and make sure it works, use javascript. some people may find it annoying for like a "form" with many inputs, as already mentioned. I think it's best use would be on the search input box on a page, especially if you found people often used the "quick search" box or whatever, if you have one.
     
Grizzled Veteran
Join Date: Nov 2003
Location: Hebburn, UK
Status: Offline
Reply With Quote
Mar 14, 2004, 05:01 AM
 
I originally assumed he meant moving the mouse pointer, but since it can't be done, decided to answer the question as if he wanted to just focus on a text box.

I think you can use 'tabindex' to set which input is highlighted first - not sure though...
Just who are Britain? What do they? Who is them? And why?

Formerly Black Book
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:01 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2