Hi! I'm new to Javascript and wanted to make a small validation for my form. Here is what I have constructed thus far:
When the submit button is pressed, the form is still sent, but there are blank feilds for name and email. Suggestions? .:TUCK:.
Code:
<script LANGUAGE="JAVASCRIPT">
<!-- hide script from older bowsers
function validateForm(form){
ret = true;
if ( form.name.value == "" ){
alert("A name is required.");
ret = false;
}
if ( form.email.value == "" ){
alert("An email address is required.");
ret = false;
}
return( ret);
}
// end of code hiding -->
</script>
<form action="send.php" method="post" name="sendMassage">
<input type="hidden" name="date" value="<?php $now = time(); localtime(time(),true); getdate(); print date("m/d/y, g:i:s A"); ?>">
<input type="hidden" name="ip" value="<?php print $HTTP_SERVER_VARS['REMOTE_ADDR']; ?>">
<tr>
<th align="right">Name :</th><th colspan="3" align="left"><input type="text" name="name"></th>
</tr>
<tr>
<th align="right">Email :</th><th colspan="3" align="left"><input type="text" name="name"></th>
</tr>
<tr>
<th align="right">Phone :</th><th colspan="3" align="left"><input type="text" name="name"></th>
</tr>
<tr>
<th valign="top" align="right">Message :</th><th colspan="3" align="left"><textarea name="message" rows="7" cols="45"></textarea></th>
</tr>
<tr>
<td colspan="4" align="center"><input class="colorbtn" type="submit" name="submit" value="Send" onSubmit="validateForm(this.form)"> <input class="colorbtn" type="reset" value="Clear"></th>
</tr>
</form>
When the submit button is pressed, the form is still sent, but there are blank feilds for name and email. Suggestions? .:TUCK:.