Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
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

 Answers
42

Your brace should be after function validateForm() and after the if, and at the end of the function. Overall, the braces are screwed in this example.



Lay your code out so the opening and closing braces match up and make sense to you.


[#85201] Thursday, May 31, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tristani

Total Points: 318
Total Questions: 95
Total Answers: 106

Location: Saint Lucia
Member since Wed, Feb 8, 2023
1 Year ago
;