0

Hi all
This won't validate!! any suggestions? it for some reason doesn't call the ValidateFrom function... so the error lies either with the manner in which i'm calling the javascript functions or the javascript itself.

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="style.css" rel="stylesheet" type="text/css">
<title>User Details</title>
<script type="text/javascript">
 
function validateForm(){
 
  var x=document.forms["myForm"]["username"].value
if (x==null || x=="")
  {
  alert("username must be filled out");
  return false;
  }
 
  var y=document.forms["myForm"]["email"].value
if (y==null || y=="")
  {
  alert("email must be filled out");
  return false;
  }
 
  var z=document.forms["myForm"]["firstname"].value
if (z==null || z=="")
  {
  alert("firstname must be filled out");
  return false;
  }
 
  var a=document.forms["myForm"]["surname"].value
if (a==null || a=="")
  {
  alert("surname must be filled out");
  return false;
  }
 
  var b=document.forms["myForm"]["birthday"].value
if (b==null || b=="")
  {
  alert("birthday must be filled out");
  return false;
  }
 
  var c=document.forms["myForm"]["password"].value
if (c==null || c=="")
  {
  alert("password must be filled out");
  return false;
  }
 
  var d=document.forms["myForm"]["pwdconfirm"].value
if (d==null || d=="")
  {
  alert("pwdconfirm must be filled out");
  return false;
  }
 
  var e=document.forms["myForm"]["gender"].value
if (e=="nothing")
  {
  alert("gender must be chosen");
  return false;
  }
  validateEmail();
}
 
function validateEmail(){
	echo "i got to here.. ";
	var h=document.forms["myForm"]["email"].value
	var atpos=h.indexOf("@");
	var dotpos=h.lastIndexOf(".");
	if (atpos<1 || dotpos<atpos+2 || dotpos+2>=h.length){
		alert("Not a valid e-mail address");
		return false;
	}
validateDate();
 }
 
 function validateDate(){
 var chkdate = document.forms["myForm"]["birthday"].value
	if(chkdate.match(/^[0-9]{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])/)){
	  alert("works out");
	}
	else{
		alert("date format is wrong");
		return false;
	}
 }
 
</script>
</head>
<body>
<div class="center">
<h1>Enter your details user!!</h1>
<form name = "myForm" id = "myForm" action = "display.php" onsubmit = "return validateForm()"  method = "post" novalidate="novalidate">
<table border = "1">
<tr>
	<td>Username: </td>
	<td><input type="text" name="username" /></td>
</tr>
<tr>
	<td>Email: </td>
	<td><input type="email" name="email" /></td>
</tr>
<tr>
	<td>First name: </td>
	<td><input type="text" name="firstname" /></td>
</tr>
<tr>
	<td>Surname: </td>
	<td><input type="text" name="surname" /></td>
</tr>
<tr>
	<td>Date of Birth(YYY-MM-DD): </td>
	<td><input type="date" name="birthday" /></td>
</tr>
<tr>
	<td>Password: </td>
	<td><input type="password" name="password" /></td>
</tr>
<tr>
	<td>Password Confirm: </td>
	<td><input type="password" name="pwdconfirm" /></td>
</tr>
<tr>
	<td>Gender: </td>
	<td><select name="gender">
			<option value="nothing"></option>
			<option value="Male">M</option>
			<option value="Female">F</option>
		</select>
	</td>
</tr>
<tr>
	<td>Press to Continue:</td>
	<td><input type="submit" value="submit" /></td>
</tr>
</table>
</form>
</div>
</body>
</html>
2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Airshow
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.