submitting form after validation with onsubmit function - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Submit

Description

submitting form after validation with onsubmit function

Demo Code

ResultView the demo in separate window

<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>

Related Tutorials