Javascript custom validator problem on DropDownList

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Assimalyst

    Javascript custom validator problem on DropDownList

    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 validateSurgeon NameDDL(oSrc, args)
    {
    args.IsValid = ([surgeonNameDDL. SelectedIndex].Value != "0");
    }

    However, this comes back invalid, for all selection.

    Thanks.

  • Mick White

    #2
    Re: Javascript custom validator problem on DropDownList

    Assimalyst wrote:[color=blue]
    > 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 validateSurgeon NameDDL(oSrc, args)
    > {
    > args.IsValid = ([surgeonNameDDL. SelectedIndex].Value != "0");
    > }
    >[/color]

    function somethingSelect ed(dropdownlist ){
    return dropdownlist.se lectedIndex>0;
    }

    function validateForm(fo rm){
    var msg="";
    if(!somethingSe lected(form.SEL ECTNAMEHERE)) {
    msg+="Please select a surgeon\n";
    }

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


    Comment

    Working...