0

How To show Errors on same page in PhP using javascript for form validations

The form is coffe shop order with the action attribute set to another page which displays the output in php. The form validation has to be done using JavaScript and the error message needs to be displayed on the same page. My problem is that it always goes to the next php page when i click on submit button. Can Anyone please help me out ???

25th Mar 2017, 2:23 PM
Giriraj Bhagat
Giriraj Bhagat - avatar
2 odpowiedzi
0
javascript ---------------- function validateForm() {     var x = document.forms["myForm"]["name"].value;     if (x == "") {         alert("Name must be filled out");         return false;     } } Html form ------------- <form name="myForm" action="process.php" onsubmit="return validateForm()" method="post"> Name: <input type="text" name="name"> <input type="submit" value="submit"> </form>
25th Mar 2017, 5:19 PM
Aung Aung
Aung Aung - avatar
0
pre-thankyou...
16th Jul 2018, 5:37 AM
Surya Suprince
Surya Suprince - avatar