www.webdeveloper.com
Results 1 to 2 of 2

Thread: Form submits despite false return

  1. #1
    Join Date
    Jan 2011
    Posts
    27

    Form submits despite false return

    Hey All,

    I am working to get my form validated with JS and it seems that although the form returns false and I get the alert that a field is missing, the form still processes...hopefully you guys are seeing something im not.

    Code:
    function validate(){
    		with(document.forms[0]){
    			if(requiredCheck(fnameField) && 
    				requiredCheck(lnameField) && 
    				requiredCheck(addressField) &&
    				isNum(fnameField) &&
    				isNum(lnameField) && 
    				emailCheck(emailField) &&
    				checkForCharacter (emailField, "@") &&
    				checkForCharacter (emailField, ".")){
    				setCookie(); // Set form cookie
    			return true;
    		}else{
    			return false;
    		}
    	}
    	}
    
    <form action="form-processor.php" id="contactForm" method="post" onsubmit="validate();">
                	<p><span class="reqField">*</span>First Name: <input type="text" name="fnameField" id="fnameField" size="50" /><br /><br />
                    <span class="reqField">*</span>Last Name: <input type="text" name="lnameField" id="lnameField" size="50" /><br /><br />
                    <span class="reqField">*</span>Email: <input type="text" name="emailField" id="emailField" size="55" /><br /><br />
                    <span class="reqField">*</span>Address:<br /><textarea name="addressField" id="addressField" cols="47" rows="4"></textarea><br /><br />
                    Inquiry:<br /><textarea name="inquiryField" id="inquiryField" cols="47" rows="4"></textarea><br /><br />
                    <input type="submit" value="Submit" />
                    <input type="reset" value="Reset" />
                </form>

  2. #2
    Join Date
    Nov 2002
    Location
    Flint, Michigan, USA
    Posts
    607
    Change
    Code:
    onsubmit="validate();"
    to
    Code:
    onsubmit="return validate();"

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles