Jump to content

Validation Not Working


obi_wan

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

var firstName	 = document.getElementById("firstName").value;if(. . . firstName.value == null || firstName.value =="")

firstName is the value. It doesn't also have a value.

Thanks a lot that did the trick, I will follow those tips religiously!
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...