Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
Why Does This Code Not Work?
So I am learning how to do Form Validation. I typed the following in the Tryit Editor v1.4:
<head>
<title>A Simple Form with JavaScript Validation</title>
<script type="text/javascript">
<!--
function validate_form ()
{
valid = true;
if( document.contact_form.contact_name.value == "" )
{
alert ("Incorrect!");
valid = false;
}
return valid;
}
//-->
</SCRIPT>
</HEAD>
<FORM name="contact_form" method="POST" action="admin@fsxnetwork.awardspace.com" onSubmit="return validate form ();">
<h1>Please Enter Your Name</h1>
<p>Your Name: <input type="text" name="contact_name">
<input type="submit" name="send" value="Send Details">
I typed this because I am learning how to make it in a tutorial. The tutorial source code is:
<html>
<head>
<title>A Simple Form with JavaScript Validation</title>
<script type="text/javascript">
<!--
function validate_form ( )
{
valid = true;
if ( document.contact_form.contact_name.value == "" )
{
alert ( "Please fill in the 'Your Name' box." );
valid = false;
}
return valid;
}
//-->
</script>
</head>
<body bgcolor="#FFFFFF">
<form name="contact_form" method="post"
action="/cgi-bin/articles/development/javascript/form-validation-with-javascript/contact_simple.cgi"
onSubmit="return validate_form ( );">
<h1>Please Enter Your Name</h1>
<p>Your Name: <input type="text" name="contact_name"></p>
<p><input type="submit" name="send" value="Send Details"></p>
</form>
</body>
</html>
Is there anything wrong with the first code (the code I typed) that makes it not validate the form?
Thanks
1 Answer
- Germann ALv 71 decade agoFavorite Answer
Notice ANY difference between your code
onSubmit="return validate form ();">
and the tutorial code
onSubmit="return validate_form ( );">
???