I have javascript validating the following form. When the email is not entered an alert box is thrown up stating “not a valid email”. however the action “collectMailPHP.php” is still executed. Can anyone help?
Here is the javascript:
<script type=“text/javascript”>
function validate_email(field,alerttxt)
{
with (field)
{
apos=value.indexOf("@");
dotpos=value.lastIndexOf(".");
if (apos<1||dotpos-apos<2)
{alert(alerttxt);return false;}
else {return true;}
}
}
function validate_form(thisform)
{
with (thisform)
{
if (validate_email(email_client,“Not a valid e-mail address!”)==false)
{email.focus();return false;}
}
}
</script>
Here is the form;
<form action=“collectMailPHP.php” method=“post” onsubmit=“return validate_form(this);”>
<fieldset>
<legend> <span class=“style1”>Find Out More</span> </legend>
<ul>
<li>
<input type="text" class="contact_select" onfocus="if (this.value=='-Enter Email Address-'){this.value='';}" onblur="if (this.value==''){this.value='-Enter Email Address-';}" border="2" name="email_client" tabindex="1" value="-Enter Email Address-"></li>
<li>
<select class="contact_select" name="subject">
<option>I'm interested in...</option>
<option>Bingo Machines</option>
<option>Raffle Equipment</option>
<option>Arcade Games</option>
<option>Electronic Promotions</option>
<option>Other products</option>
</select>
</li>
<div id=“submit_2”>
<input type=“submit” border=“1” value=“Submit” tabindex=“5” />
</div>
</ul>
</fieldset>
</form>