mrong
asked on
DropDown box in ASP
Greeting,
I have the a dropdown box in asp and it populates data from a database as the following.
<TD width="414" colspan="3" style="height: 23px">
<SELECT name="Bldg" style="width: 536px">
<%call getBLDG%>
</SELECT></TD>
I use the following javascript to make the field required before regardless if the user selects item from dropdown list or not, the form always popup message "Building One is a required field,and can't be empty." Please suggest.
if(isWhitespace(document.f rmUser.Bld g.value,tr ue))
{
alert("Building One is a required field,and can't be empty.");
return false;
}
I have the a dropdown box in asp and it populates data from a database as the following.
<TD width="414" colspan="3" style="height: 23px">
<SELECT name="Bldg" style="width: 536px">
<%call getBLDG%>
</SELECT></TD>
I use the following javascript to make the field required before regardless if the user selects item from dropdown list or not, the form always popup message "Building One is a required field,and can't be empty." Please suggest.
if(isWhitespace(document.f
{
alert("Building One is a required field,and can't be empty.");
return false;
}
Curious as to what the function isWhitespace does. But if you are checking to see if the field has been filled out, the code below should suffice.
if(document.frmUser.Bldg.value == '')
{
alert("Building One is a required field,and can't be empty.");
return false;
}
ASKER
Big Monty,
it doesn't work.
Thanks.
it doesn't work.
Thanks.
you actually shouldnt need the isWhitespace function, as you control all of the values in the dropdown, I would remove it and do:
if(document.frmUser.Bldg.o ptions[doc ument.frmU ser.Bldg.s electedInd ex].value == '' )
{
alert("Building One is a required field,and can't be empty.");
return false;
}
if(document.frmUser.Bldg.o
{
alert("Building One is a required field,and can't be empty.");
return false;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Does one of your options include a value? If your page renders option values, something is chosen on submit. The first value is the default unless. I would make the first value something you can check. Also, js can be disabled so you want to check this serverside and make sure you are accepting a value that is in the proper range.
<SELECT name="Bldg" style="width: 536px">
<!-- < % call getBLDG % > -->
<option value="0">No Option Selected</option>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
</SELECT>
if(isWhitespace(document.f
{
alert("Building One is a required field,and can't be empty.");
return false;
}