javascript checking empty fields

Results 1 to 2 of 2

Thread: javascript checking empty fields

  1. #1
    Join Date
    Dec 1969

    Default javascript checking empty fields

    Whats the best way of checking multiple fields one after another I have email field working but need username and password fields checked for null values?<BR><BR>&#060;SCRIPT LANGUAGE =Javascript&#062;<BR>function checkAddress()<BR>{<BR> strAddress = document.forms[ 0 ]. elements["txtEmail"].value;<BR> if (strAddress.indexOf("@") != -1) // contains @ somewhere<BR> return true<BR> else<BR> {<BR>alert ("you need a valid email address");<BR>return false<BR> }<BR>}<BR><BR>&#060;/SCRIPT&#062;<BR><BR>bearing in mind this bit here<BR>&#060;FORM method="post" onsubmit = "return checkAddress()" action="register.asp?add=true"&#062;

  2. #2
    Join Date
    Dec 1969

    Default RE: javascript checking empty fields--just keep ch

    Hope this helps it validates three items:<BR>function rtrCheck1()<BR>{<BR>//Check password has something <BR> if (document.rtrFrm1.Pword.value.length == 0){<BR> alert("A Password is required!!");<BR> document.rtrFrm1.Pword.focus();<BR> return false<BR> } <BR> else<BR>//If it has something must be at least six chars <BR> if (document.rtrFrm1.Pword.value.length &#060; 6 &#124&#124 document.rtrFrm1.Pword.value.length &#062; 8){<BR> alert("Password must be between 6 and 8 characters long!!");<BR> document.rtrFrm1.Pword.focus();<BR> return false<BR> } <BR>//If they can&#039;t find a name in drop down, they choose other. If they choose other they<BR>//must enter an email address. <BR> if (document.rtrFrm1.RaterName.value == "Other"){<BR> if (document.rtrFrm1.otherEmailAddr.value == ""){<BR> alert("Other Email Address is required!!"); <BR> document.rtrFrm1.otherEmailAddr.focus();<BR> return false<BR> }<BR> }<BR>//They must select something from the drop down list <BR> if (document.rtrFrm1.RaterName.value == "Choice"){<BR> alert("You must select a name or Other!!"); <BR> document.rtrFrm1.RaterName.focus();<BR> return false<BR> }<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