Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set focus to form element!

Status
Not open for further replies.

HuggerFanta

Technical User
Apr 22, 2002
87
0
0
SE
Hello!
I´m trying to set focus to a form element, plain input field. But it just dose not focus that element.

If someone has the code for focus form element, please post it here!

Thanks
HuggerFanta

--------------------------------------
Kind regards;
HuggerFanta
 
Code:
document.forms["your_form_name"].element_name.focus();

be aware that JavaScript is a case sensitive language therefore it is absolutely important that function names and variable names are written with the correct casing.
 

For IE 5.0 and above, your field must have a tabIndex attribute set for focus to be set programatically.

Add one in, something like this:

Code:
<input type="text" tabIndex="1">

And it should work (assuming, of course, that your focussing code is correct ;o)

Hope this helps,
Dan
 
it's not really necessary to add a tabindex attribute...
 
I've tested it just now and it works without...
 

How queer... I've tested it and it seems to work fine without the tabIndex (caveat: on *my* test code here).

However, I've definately had situations recently where it has not worked - more specifically on some menu code I was working on, and adding the tabIndex attribute fixed it... So sometimes you do need to add it.

HuggerFanta: I suggest you try adding it, and seeing if this is one of those situations where it is needed before focussing will occur.

Hope this helps,
Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top