Jump to content

Select (drop list) focus


Elemental

Recommended Posts

Hey Folks, I'm working on a form or rather on validating the form fields since that's where I'm having the issue, thus the question; in truth I have a number of questions regarding this but I'm going to address them one at a time or I'll get lost and confused and won't learn a thing.Of course if any of you know where I can go and learn more advanced, okay not too advanced, forms and the Javascript that goes along with them I'll be forever thankful...For now, however, how do I set focus on a select field if no option was selected.My HTML:

<select tabindex="" name="state" id="state"><option value="" selected="true"></option><option value="AK">AK</option> etc, etc, etc, ...</select>

I left the rest out, of course...My java script:

if (document.getElementById("state").value == ""){alert("Please select your 'State'");document.getElementById("state").focus();return false;}

What do I need to add / change so that the state field, if not selected, gets the focus it deserves?Peace,Elemental

Link to comment
Share on other sites

The script is fine, at least in FF3. Where and under what circumstances are you calling it? If you're getting the alert, then it's working as well as your browser will let it. If you're not getting the alert, the lines aren't getting called, and that problem lies outside the snippets you gave us.

Link to comment
Share on other sites

The script is fine, at least in FF3. Where and under what circumstances are you calling it? If you're getting the alert, then it's working as well as your browser will let it. If you're not getting the alert, the lines aren't getting called, and that problem lies outside the snippets you gave us.
Deirdre's Dad, Thank you for the reply.Sorry, I should have mentioned that little bit of info...The alert is called, but in IE, and only in IE, the field does not get focused after you okay out of the alert box, and that's what I'm trying to correct. FF works fine and both Safari and Opera not only do they set the focus they bring the field center stage.Peace,Elemental
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...