I have a validation code for an email and checkbox field on a form. The code check that all required fields (email and checkbox) are completed and when they are not showing the alert.
But when it is all completed, when you press the send button, it does not execute the action "mailer.php".
I leave the validation code here, maybe i have missed something and therefore do not run the action.
Code:
<script type="text/javascript">
function validar()
{
var email = document.getElementById('email');
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (!filter.test(email.value)) {
alert('Por favor compruebe la dirección de email');
email.submit;
return false;
}
elemento = document.getElementById("checkbox");
if( !elemento.checked ) alert('Por favor acepte el aviso legal'); {
return false;
}
return true;
}
</script>
What's email.submit; for?
Maybe you meant email.focus();
if( !elemento.checked ) {
alert('Por favor acepte el aviso legal');
return false;
}
How is the JavaScript form validation handler invoked from your HTML?
You should have
<form name="myform" action="mailer.php" onsubmit="return validar();">
....
....
<input type="submit" name="btnsubmit" value="Send">
</form>
Bookmarks