You cannot get boolean value from javascript. What you need to do is prepare a div error in advance. Something like that:
<body> <form name="myForm" action="demo_form.asp" onsubmit="return validateForm();" method="post"> Email: <input type="text" name="email"> <div id="error"></div> <input type="submit" value="Submit"> </form>
Add css to it to hide it. Then in your validation form, use javascript to change the HTML error code.
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length) { document.getElementById("error").innerHTML="Not a valid e-mail address"; return false; }
"return false"; the part must inform the form not to file. As mentioned in other answers, PHP and Javascript do not interact. PHP - server side, Javascript - client side. They do not talk to each other. However, they can modify the HTML. Just remember, Javascript always works in the browser. Therefore, if he needs to send things to PHP, you need to use AJAX to call the server side of the PHP script and send the information in this way. However, most of the time when you use Javascript, it is not PHP that needs information, it is a user. Therefore, using Javascript to change the HTML does the trick.
Daniel Bingham
source share