Handle form submit action with onsubmit - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Submit

Description

Handle form submit action with onsubmit

Demo Code

ResultView the demo in separate window

<html>
   <head></head>
   <body> 
      <p>When you submit the form, a function is triggered which alerts some text.</p> 
      <form action="demo_form.asp" onsubmit="return myFunction(this)">
          Enter name: /*from  ww w  . j  a va2  s .c o  m*/
         <input type="text" name="fname"> 
         <input type="submit" value="Submit"> 
      </form> 
      <script>
    function myFunction(form) {
        console.log(form.fname.value);
        return false;
    }

      </script>  
   </body>
</html>

Related Tutorials