Thread: form validation

    #1
  1. No Profile Picture
    Contributing User
    ASP Discoverer (100 - 499 posts)

    Join Date
    Dec 2006
    Location
    Jacksonville
    Posts
    409
    Rep Power
    20

    form validation


    hey all. i can't figure out this bit -- i'm trying to ensure the passwords match before allowing the form to submit. (i also check it on the server side because i know javascript can be disabled..). everything else works (first name, last name, etc) but FOR SOME REASON password does not. i get the error message, but the form still submits. if the name or email or phone number fail, the form doesnt submit, and the field gets put in focus, but password is not doing that. i put it at the top of the script to try and debug, and i've moved around the different validation sets and tried every way i know how, but i just cant get it.

    any tips would be great.

    Code:
    function checkEmployee(frm)
    	{
    		
    		//password
    		p1 = document.getElementById("pass1").value;
    		p2 = document.getElementById("pass2").value;
    		if (p1 != p2) {
    			alert("Passwords do not match.");
    			p1.focus();
    			return false;
    		}
    		
    		<% fieldName = "employerPIN"
    		errorMessage = "5 digit employer PIN is required." %>
    		if (frm.<% = fieldName %>.value.length != 5)
    		{
    			alert("<% = errorMessage %>");
    			frm.<% = fieldName %>.focus();
    			return false;
    		}
    		<% fieldName = "contactFirstName"
    		errorMessage = "Your first name is required." %>
    		if (frm.<% = fieldName %>.value == 0)
    		{
    			alert("<% = errorMessage %>");
    			frm.<% = fieldName %>.focus();
    			return false;
    		}
    		<% fieldName = "contactLastName"
    		errorMessage = "Your last name is required." %>
    		if (frm.<% = fieldName %>.value == 0)
    		{
    			alert("<% = errorMessage %>");
    			frm.<% = fieldName %>.focus();
    			return false;
    		}
    		<% fieldName = "contactPhone"
    		errorMessage = "Your phone number is required." %>
    		if (frm.<% = fieldName %>.value == 0)
    		{
    			alert("<% = errorMessage %>");
    			frm.<% = fieldName %>.focus();
    			return false;
    		}
    		
    		//email validation
    		var email = document.getElementById('contactEmail');
    		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    		if (!filter.test(email.value)) {
    			alert('Please provide a valid email address.');
    			email.focus();
    			return false;
    		}
    		
    		return true;
    	}
  2. #2
  3. No Profile Picture
    Contributing User
    ASP Discoverer (100 - 499 posts)

    Join Date
    Dec 2006
    Location
    Jacksonville
    Posts
    409
    Rep Power
    20
    over 40 views and not one comment?
  4. #3
  5. No Profile Picture
    Contributing User

    Join Date
    Jun 2011
    Location
    Pasig City, Philippines
    Posts
    26
    Rep Power
    0
    Hi!

    Maybe you're missing the .value property in order to get the values of the two text fields.

    Try:

    if (p1.value != p2.value){
    ...
    }


    I hope this helps. Thank you.

Similar Threads

  1. Form validation
    By phoenixaz in forum ASP Development
    Replies: 23
    Last Post: February 16th, 2008, 07:15 PM
  2. Asp form validation
    By phatmike10 in forum ASP Development
    Replies: 2
    Last Post: June 1st, 2007, 12:29 PM
  3. Form validation
    By Zoe-Alyssa in forum ASP Development
    Replies: 1
    Last Post: August 16th, 2006, 06:19 AM
  4. How to call validation from one form to another form
    By itskhushi in forum .NET Development
    Replies: 3
    Last Post: February 23rd, 2006, 01:35 AM
  5. Form validation works, field validation doesn't
    By abacus in forum HTML, JavaScript And CSS Help
    Replies: 13
    Last Post: June 18th, 2005, 09:50 AM

IMN logo majestic logo threadwatch logo seochat tools logo