I find this code in W3Schools. It's about form validation with Javascript.
When the user tape wrong mail format, an alert is appear.
When I check the code I see on form onsubmit="return validateForm();, well the function return false in error case.
So my question is how to get the boolean value from javascript to use it in PHP to write error message instead of use of message box.
This is my code:
<html>
<head>
<script type="text/javascript">
function validateForm()
{
var x=document.forms["myForm"]["email"].value
var atpos=x.indexOf("@");
var dotpos=x.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
{
alert("Not a valid e-mail address");
return false;
}
}
</script>
</head>
<body>
<form name="myForm" action="demo_form.asp" onsubmit="return validateForm();" method="post">
Email: <input type="text" name="email">
<input type="submit" value="Submit">
</form>
</body>
</html>
Thanks in advance.
Ali