154
rated 0 times
[
157]
[
3]
/ answers: 1 / hits: 76647
/ 12 Years ago, fri, june 1, 2012, 12:00:00
I was doing the testing for the first time. I read the this code and made one of my own from it. The thing is that its not giving any error even if the fields are left empty.
Here is my fiddle.
Please help out. Thanks.
<!DOCTYPE html>
<html>
<head>
<script type=text/javascript>
{function validateForm()
var x=document.forms[myForm][name].value;
if (x==null || x==)
{
alert(Name must be filled out);
return false;
}
var y=document.forms[myForm][password].value;
{
if (y==null || y==)
alert(Password name must be filled out);
return false;
}
</script>
</head>
<body>
<form name=myForm action=demo_form.asp onsubmit=return validateForm() method=post>
Name*: <input type=text name=name> <br>
Password*: <input type=password name=password><br>
Email: <input type=text name=email><br>
<input type=submit value=Submit>
</form>
</body>
</html>
More From » forms