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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pull down menu validation 3

Status
Not open for further replies.

peach255

Programmer
Joined
Jan 20, 2003
Messages
29
Location
US
Hi. I have a pull down menu in my form. Is it possible if I can have the default selection in the menu be set to a blank? And how do I validate the form to make sure the user did choose a selection from the pull down menu? I have the following code to validate a text box, but how about validate pull down menus? Thank you!

function checkform(form)
{
if(form.fname.value == "")
{
alert('You forgot to enter your First Name?');
form.fname.focus();
return false;
}
return true;

}
 
use selectedindex for validating dropdowns
function checkform(form)
{
if(myform.fname.options[form.fname.selectedIndex].value == "")
{
alert('You forgot to enter your First Name?');
myform.fname.focus();
return false;
}
return true;

} _______________________________________________
{ str = "sleep is good for you. sleep gives you the energy you need to function";
ptr = /sleep/gi;Nstr = str.replace(ptr,"coffee");alert(Nstr); }

_______________________________________________
for the best results to your questions: FAQ333-2924

 
use Onpnt's code to check and add this line just after your SELECT opening tag to add a default blank selection :
Code:
<OPTION value=&quot;&quot; selected>---Choose one---</option>[/code) Water is not bad as long as it stays out human body ;-)
 
THanks for your quick reply!
However, although I don't have any of the selection in my pull down menu selected by default, it displays the 1st selection on my choice. For ex., for &quot;Month&quot;, it displays &quot;January&quot;. Therefore, if I don't select any other month, it pass &quot;January&quot; as the variable.
How can I change this? Can I have a empty space as the default selction? My code for the selection pull down menu is as follow.

<FONT face=Tahoma size=2>*Move Date</FONT>
<SELECT name=month id=&quot;month&quot;>
<option value=&quot;January&quot;>January
<option value=&quot;February&quot;>February
</SELECT>

Thanks!
 
Targol gave you the answer to that one
<SELECT name=month id=&quot;month&quot;>
<option value=&quot;&quot; selected>---Choose one---</option>
<option value=&quot;January&quot;>January
<option value=&quot;February&quot;>February
</SELECT> _______________________________________________
{ str = &quot;sleep is good for you. sleep gives you the energy you need to function&quot;;
ptr = /sleep/gi;Nstr = str.replace(ptr,&quot;coffee&quot;);alert(Nstr); }

_______________________________________________
for the best results to your questions: FAQ333-2924

 
thanks for both of your help! It worked well for me!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top