Add action handler for form onsubmit - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Submit

Description

Add action handler for form onsubmit

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){//  w  w  w  . j a  va 2  s.  c om
document.getElementById('myform').onsubmit = function(e) {
    procesText();
    e && e.preventDefault && e.preventDefault();
    return false;
}
function procesText(){
    console.log('do some stuff');
}
    }

      </script> 
   </head> 
   <body> 
      <form id="myform">
          First Name: 
         <input type="text" id="myText" maxlength="30"> 
      </form>  
   </body>
</html>

Related Tutorials