[thelist] How to validate a <select><option>

Anthony Baratta Anthony at Baratta.com
Mon May 22 11:55:18 2000


"Wiedersheim, Leo" wrote:
> 
> Can anyone help me with validating a <select> <option>?  I can't get the
> object hierarchy syntax down,

Here's where I always go first for JavaScript help....

http://developer.netscape.com/docs/manuals/js/client/jsref/index.htm

This is hacked (not tested) - but should get you started

Function DropDownValidation {
      var okSoFar = true
      var varSelected = ""
      for (var i = 0; i < document.myForm.<name>.length; i++) {
        if (document.myForm.<name>.selectedIndex > 0) {
          if (varSelected=document.myForm.<name>.options[i].value <> "None") {
             varSelected=document.myForm.<name>.options[i].value
          }
        }
      }
      if (varSelected == "" && okSoFar) {
               okSoFar=false;
               alert("Please select an option for <name>.");
               if (window.focus){ document.myForm.<name>.focus()}
      }
      if (okSoFar==false) { return false;}
}

Replace <name> with the name of your form item. And make sure your seperator's value
is set to None.

-- 
Anthony Baratta
President
KeyBoard Jockeys
                    South Park Speaks Version 3 is here!!!
                       http://www.baratta.com/southpark
                              Powered by Tsunami