mrong
asked on
Javascript: check if selection has been made on Drop_down box(Mult-selection)
I need a Javascript function to check any selection has been made on Drop_down box in asp.
Thanks.
Thanks.
ASKER
I am trying to force the user make selection on the dropdown list like the following, but the form is submitted without a selection.
function VerifyData()
{
if(document.frmUser.Projec tType.drop down.selec tedindex < 0 )
{
alert("Project Type is a required field,and can't be empty.");
return false;
}
else
return true;
}
<FORM ACTION="Send.asp" NAME="frmUser" METHOD="POST"
onSubmit="return VerifyData()">
function VerifyData()
{
if(document.frmUser.Projec
{
alert("Project Type is a required field,and can't be empty.");
return false;
}
else
return true;
}
<FORM ACTION="Send.asp" NAME="frmUser" METHOD="POST"
onSubmit="return VerifyData()">
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
I corrected as the following but still not working.
function VerifyData()
{
if(document.frmUser.Projec tType.drop down.selec tedIndex < 0)
{
alert("Project Type is a required field,and can't be empty.");
return false;
}
else
return true;
}
function VerifyData()
{
if(document.frmUser.Projec
{
alert("Project Type is a required field,and can't be empty.");
return false;
}
else
return true;
}
Hi
try to display the selectedIndex before the IF condition.
function VerifyData()
{
alert(document.frmUser.Pro jectType.d ropdown.se lectedInde x);
if(document.frmUser.Projec tType.drop down.selec tedIndex < 0 )
{
alert("Project Type is a required field,and can't be empty.");
return false;
}
else
return true;
}
try to display the selectedIndex before the IF condition.
function VerifyData()
{
alert(document.frmUser.Pro
if(document.frmUser.Projec
{
alert("Project Type is a required field,and can't be empty.");
return false;
}
else
return true;
}
If nothing works, try changing this line
<FORM ACTION="Send.asp" NAME="frmUser" METHOD="POST"
onSubmit="return VerifyData();">
Put semicolon after VerifyDate();
<FORM ACTION="Send.asp" NAME="frmUser" METHOD="POST"
onSubmit="return VerifyData();">
Put semicolon after VerifyDate();
//nothing selected
ELSE
//selected an item
Formname.dwopdown.options[