ainoy31 Posted September 10, 2007 Share Posted September 10, 2007 Hello- I can not figure why my javascript is not validation my entry on a form I created. Here is the javascript code: <script type = "text/javascript" language="javascript"> <!-- function Validate() { if(document.quickquote.p_address.value.length == 0) { alert("Please enter a valid street address, e.g. 7500 Canyon Drive"); return false; } if(document.quickquote.p_city.value.length == 0) { alert("Please enter city, e.g. Dallas"); return false; } if(document.quickquote.p_state.value.length == 0) || (document.quickquote.p_state.value.length < 2) || (!isLetter(document.quickquote.p_state.charAt(o))) || (!isLetter(document.quickquote.p_state.value.charAt(1)))) { alert("Please enter 2 character state abbreviation"); return false; } if(document.quickquote.p_zip.value.length != 5) && (document.quickquote.p_zip.value != 9) { alert("Invalid zipcode format, 66204"); return false; } if(document.quickquote.d_address.value.length == 0) { alert("Please enter street address, e.g. 7500 Canyon Drive"); return false; } if(document.quickquote.d_city.value.length == 0) { alert("Please enter city, e.g. Dallas"); return false; } if(document.quickquote.d_state.value.length == 0) || (document.quickquote.d_state.value.length < 2) || (!isLetter(document.quickquote.d_state.charAt(o))) || (!isLetter(document.quickquote.d_state.value.charAt(1)))) { alert("Please enter 2 character state abbreviation"); return false; } if(document.quickquote.d_zip.value.length != 5) && (document.quickquote.d_zip.value != 9) { alert("Invalid zipcode format, e.g. 66204"); return false; } return true; } function isLetter© { return (((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z"))) } function isDigit© { return ((c >= "0") && (c <= "9")) } // --> </script> The form code is: <form name="quickquote" action="process1.php" method= "post" onSubmit="return Validate();"> <div class = "content"> <h2>Enter your information to receive your QuickQuote!</h2><br> <p>Pickup Location</p> <br> Address: <input type="text" name="p_address" size="30" /><br> City: <input type="text" name="p_city" size="30" /><br> State: <input type="text" name="p_state" size="5" /><br> Zip: <input type="text" name="p_zip" size="5" /><br> <br> <br> <p>Destination Location</p> <br> Address: <input type = "text" name = "d_address" size = "30" /><br> City: <input type = "text" name = "d_city" size = "30" /><br> State: <input type="text" name="d_state" size="5" /><br> Zip: <input type="text" name="d_zip" size="5" /><br> <br> <center><input type = "Submit" name = "Submit" value = "Submit" /></center> </div> </form> If I leave the address field empty, the form still gets processed. Much appreciation. Link to comment https://forums.phpfreaks.com/topic/68706-form-entry-validation/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.