[thelist] JS Form Validation

Joshua Hmielowski jhmielowski at comcast.net
Fri Jul 2 13:34:57 CDT 2004


So after trying MULTIPLE different scripts , some which worked on 
certain browsers and not others.
Some which did not work at all. For some reason both Brian's and 
Chris's script did not work for me.
And It might have been a matter of just misspelling a word, but after 
much deliberation, I
dissected both scripts to come up with something that worked for me.
Thanks guys.


The Function...

function validate() {
     if (document.myForm.realname.value == '') {
        alert('Please complete the First Name field');
         document.myForm.realname.focus();
          return false; }

   else if (document.myForm.lastname.value == '') {
         alert('Please complete the Last Name field');
         document.myForm.lastname.focus();
          return false; }

         else
         document.myForm.action = "mailto.php";
         return true; }

Form...
<form  name="myForm"  method="POST"  action=""  onsubmit="return 
validate();">

		<input type="hidden" name="recipient" value="blahblah at blah.com">

		<input type="hidden" name="subject" value="TEST">

		<input type="hidden" name="redirect" 
value="http://www.roaringforkvehicles.com/thankyou.html">
								
		<input type="text" name="realname" size="5"><br>
		<input type="text" name="lastname" size="5">
								
		<input type="submit" name="submit">
</form>



More information about the thelist mailing list