Jump to content

Validation Not Working


obi_wan
 Share

Recommended Posts

Hey every one I am creating a simple form validation and for some reason it executes an if statement even when the conditions are met. Any help would be awesome.

function validateBannerForm(){	// initialize variables	var at		= document.getElementById("emailAddress").value.indexOf("@");	var zip 		= document.getElementById("zipCode").value;	var firstName 	= document.getElementById("firstName").value;	var lastName 	= document.getElementById("lastName").value;	var submitOK	  = "true";		// check first name is not empty, null and is not > 20	if(firstName.length > 20 || firstName.value == null || firstName.value =="")	{		// message to user if name is empty, null or more than 20 characters		// display error panel div with specific message		var errorMessage = document.getElementById("errorPanel");		document.getElementById('errorPanel').style.visibility="visible";		errorMessage.innerHTML = "Please provide us with your name, also your first name cannot be more than 20 letters.";		submitOK="false";	}		// check last name is not empty, null and is not > 30	if(lastName.length > 30 || lastName.value == null || lastName.value =="")	{		var errorMessage = document.getElementById("errorPanel");		document.getElementById('errorPanel').style.visibility="visible";		errorMessage.innerHTML = "What's your last name, also your last name cannot be more than 30 letters.";		submitOK="false";	}	else	{		alert("Carry On Lad");	}	}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...