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!

Form Validation

Status
Not open for further replies.

aspmonster

IS-IT--Management
Dec 11, 2003
25
0
0
US
How do I validate a drop down option box.
Right now..I use this for all my fields..but thats not correct. this one checks for blank fields...
Help....

if (document.frmAdd.Department.value == "") {
alert("You must enter Employee's Department or Team Name!");
return false;

}
 
Same way as you just did it.

Each item in the dropdown has a value. When one is selected, the value returned in you expression above will be something other that "". If you have specified a default value/text in the dropdown i.e. [Select a state] which has a value of 0, then you would specify:

if (document.[yourform].[yourfield].value == "0") {
alert("You must select something");
return false;

}

Dropdowns with multiple selections are a little more complex.
 
Thanks ppepin.
I tried with my code and it worked..
But I would go with urs as it looks more professional (according to my requirement).
Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top