Okay well I wrote four functions, and two of the four work but I can't seem to get the other two to work although I know my functions are right.
I'm having a problem with the execution of them!
ValidateForm() and Reset() both work
ValidateEmail() and Password checker don't work :/
And I can't seem to figure out why??
Anybody got a quick fix to help me execute this properly,,, its probably something simple and retarded
<head>
<script>
function validateForm()
{
var x=document.forms["myForm"]["email"].value;
var atpos=x.indexOf("@");
var dotpos=x.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
{
alert("Not a valid e-mail address");
return false;
}
}
</script>
<script>
function validateForm()
{
var x=document.forms["myForm"]["fname"].value;
if (x==null || x=="")
{
alert("First name must be filled out");
return false;
}
}
</script>
<script>
function checkPwdNumber(pwdNumber)
{
var i
var chr
var errorMsg = "Please enter a Nine Digit Password!"
if (pwdNumber.length != 9)
{
alert(errorMsg)
return false
}
for (i=0; i < pwdNumber.length; i++)
{
chr = pwdNumber.charAt(i)
if (chr > "9" || chr < "0")
{
alert(errorMsg)
return false
}
}
return true
}
</script>
<script type="text/javascript">
function formReset()
{
document.getElementById("myForm").reset();
}
</script>
<script>
function complete_reset()
{
alert("The form has been reset!");
}
</script>
</head>
<body>
<form id="myForm" action="demo_form.asp" name="myForm" onsubmit="return validateEmail();" method="post" onreset="complete_reset()" onSubmit="return checkPwdNumber(this.pwd.value)">
<div class="form_add">First name: <input type="text" name="fname"><br> </div>
<div class="form_add">Last name: <input type="text" name="lastname"><br> </div>
<div class="form_add">Email Address: <input type="text" name="email"><br> </div>
<div class="form_add">Password: <input type="password" name="pwd"><br></div>
<input type="submit" onclick="validateForm()" onclick="validateEmail()" value="Submit"> <br>
<input type="button" onclick="formReset()" value="Reset form"/> <br>
</body>