Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript_howto thread: Dropdown validation


Message #1 by "Jeff McFarland" <jeff@s...> on Fri, 18 Jan 2002 20:18:48
> Whats up everyone, thx for all your help with the reset button!  I am 
> working on the same form, and need to validate that something was 
selected 
> from my dropdown box.  How would you write the js code for that?
> 
> Thx a ton!
> 
> Jeff

hi! here's an idea.

given a dropdown box named mydropdownbox:

if (mydropdownbox.selectedIndex == -1) {
    // statements that will be executed if nothing is selected
else { 
    // statements that will be executed if something is selected
}

use the selectedIndex property of the dropdown box to check for the 
selected item. if there is no selected item, selectedIndex will return -1 
where as if first item is selected, selectedIndex returns 0 and so on.

  Return to Index