Form Validation

Results 1 to 3 of 3

Thread: Form Validation

  1. #1
    Join Date
    Dec 1969

    Default Form Validation

    I am JS newbie...can someone help with the following code..<BR>&#060;SCRIPT LANGUAGE=javascript&#062;<BR>// This function checks to see if all data entered in the form follows the internal business logic<BR>function validate(theForm){<BR> if (theForm.Administrator.value == "None") && (theForm.Security_Level.value == 2) {<BR> alert("Please select if this user is an Administrator!");<BR> theForm.Administrator.focus();<BR> return false;<BR> }<BR>return true;<BR>}<BR>&#060;/script&#062;<BR><BR>Both Administrator and Security_Level are drop down boxes. But when Administrator = Yes, and Security_Level = 2, the alert box does not pop up! <BR><BR>Please help

  2. #2
    Join Date
    Dec 1969

    Default Bill's mantra: DEBUG DEBUG DEBUG

    First of all, you should know that this code will not work in Netscape 4.x and older browsers, and probably not in various other browsers.<BR><BR>You can&#039;t get the .value of a &#060;SELECT&#062; in such browsers.<BR><BR>Anyway...time to add in some DEBUG code as well as fix it to be cross browser?<BR><BR>function validate(theForm)<BR>{<BR>&nbsp; &nbsp; var adm = theForm.Administrator;<BR>&nbsp; &nbsp; var admVal = adm.options[ adm.selectedIndex ].value;<BR>&nbsp; &nbsp; var sec = theForm.Security_Level;<BR>&nbsp; &nbsp; var secVal = sec.options[ sec.selectedIndex ].value;<BR><BR>&nbsp; &nbsp; alert("DEBUG: admin value is [" + admVal + "]
    " <BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + "sec level is [" + secVal + "]" );<BR><BR>&nbsp; &nbsp; if ( (admVal == "None") && (parseInt(secVal) == 2 )<BR>&nbsp; &nbsp; {<BR>&nbsp; &nbsp; &nbsp; &nbsp; alert("Please select if this user is an Administrator!");<BR>&nbsp; &nbsp; &nbsp; &nbsp; adm.focus();<BR>&nbsp; &nbsp; &nbsp; &nbsp; return false;<BR>&nbsp; &nbsp; }<BR>&nbsp; &nbsp; return true;<BR>}<BR><BR>

  3. #3
    Join Date
    Dec 1969

    Default RE: Form Validation

    The alert only pops up when admin = "Node" and security_level = 2<BR><BR>why then do you expect the alert to show when <BR>Administrator = Yes, and Security_Level = 2?<BR><BR>Bill is more than correct. Netscape 4.x is a pain in the butt for getting the value of an select. I suggest visiting or<BR>and looking for information on netscape 4.7x javascript<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts