Reputation: 399
I am getting a SyntaxError: missing ; before statement. I have no idea why I'm getting this error since my code is EXACTLY the same as in the textbook I'm using. Please help. I will post code, and comment where syntax error is:
<!DOCTYPE html>
<html lang="en">
<head>
<title> Practive</title>
<meta charset="utf-8">
<style>
input{display: block;
padding-bottom: 10px;
width: 250px;
text-align: left;}
label {float:left;}
</style>
<script type="text/javascript">
<!--
fuction validateForm() // SyntaxError: missing ; before statement
// before v
{
if (document.forms[0].userAge.value < 18){
alert ("Age is less than 18!");
return false;
} // end if
alert ("Age is valid.");
return true;
} // end function validateForm
// -->
</script>
</head>
<body>
<h1> JavaScript Form Handling </h1>
<form method="post" action="http://webdevfoundations.net/scripts/formdemo.asp" onsubmit="return validateForm();">
<label for="userName">Name: </label>
<input type="text" name="userName" id="userName">
<label for="userAge">Age:   </label>
<input type="text" name="userAge" id="userAge">
<input type="submit" value="send information" id="submit">
</form>
</body>
</html>
Upvotes: 1
Views: 3477
Reputation: 6736
You did mistake in calling function
Replace
fuction validateForm()
With
function validateForm()
You did spelling mistake in calling function.
Upvotes: 1
Reputation: 40970
write function
instead of fuction in your script like this
function validateForm()
{
if (document.forms[0].userAge.value < 18) {
alert("Age is less than 18!");
return false;
}
alert("Age is valid.");
return true;
}
Upvotes: 1
Reputation: 1672
Note this:
fuction validateForm()
should be:
function validateForm()
You forgot the N in word function and fixing that is solution to your problem. :)
Upvotes: 4