I want to validate my form so i call validateForm() using onsubmit of the form. It displays the alert but doesn't cancel the submit. What could be the problem?
function validateForm()
{
var x=document.forms["contactform"]["name"].value;
if (x==null || x=="" || x=="Name")
{
alert("First name must be filled out");
return false;
}
else
return true;
}
<form id="contactform" method="post" action="submitemail.php" onsubmit="return validateForm()">
<fieldset>-
<label for="name">Name</label>
<input type="text" name="name" id="name" value="Name" onfocus="if(this.value=='Name')this.value='';" onblur="if(this.value=='')this.value='Name';" />
<label for="email">E-mail</label>
<input type="text" name="email" id="email" value="Email" onfocus="if(this.value=='Email')this.value='';" onblur="if(this.value=='')this.value='Email';" />
<label for="subject">Subject</label>
<input type="text" name="subject" id="subject" value="Subject" onfocus="if(this.value=='Subject')this.value='';" onblur="if(this.value=='')this.value='Subject';" />
<label for="message"></label>
<textarea name="message" id="message" cols="30" rows="10"></textarea>
<div id="error"></div>
<input type="submit" name="submit" id="submit" value="Send" />
</fieldset>
</form>