Javascript examples for DOM HTML Element:Input Submit
submitting form after validation with onsubmit function
<html> <head> <script> function validateForm()//from www .j a va 2 s .c om { var x=document.forms["myForm"]["fname"].value; if (x==null || x=="") { console.log("First name must be filled out"); return false; } } </script> </head> <body> <form name="myForm" action="demo_form.asp" onsubmit="return validateForm()" method="post"> First name: <input type="text" name="fname"> <input type="submit" value="Submit"> </form> </body> </html>