Javascript custom validator problem on DropDownList

A

Assimalyst

Hi,

I'm pretty new to javascript and i'm struggling to get a custom
validator working.

I have a dropdownlist populated by a datareader, the top value of which
is always "Please Select..." at index 0.

How can i code a validator to be invalid if "Please Select..." is
selected, but valid for any other value?

Here is my attempt:

function validateSurgeonNameDDL(oSrc, args)
{
args.IsValid = ([surgeonNameDDL.SelectedIndex].Value != "0");
}

However, this comes back invalid, for all selection.

Thanks.
 
M

Mick White

Assimalyst said:
Hi,

I'm pretty new to javascript and i'm struggling to get a custom
validator working.

I have a dropdownlist populated by a datareader, the top value of which
is always "Please Select..." at index 0.

How can i code a validator to be invalid if "Please Select..." is
selected, but valid for any other value?

Here is my attempt:

function validateSurgeonNameDDL(oSrc, args)
{
args.IsValid = ([surgeonNameDDL.SelectedIndex].Value != "0");
}

function somethingSelected(dropdownlist){
return dropdownlist.selectedIndex>0;
}

function validateForm(form){
var msg="";
if(!somethingSelected(form.SELECTNAMEHERE)) {
msg+="Please select a surgeon\n";
}

....
if(msg){alert(msg);return false;}
return true;
}
Mick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top