call function after filling form and pressing enter - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Submit

Description

call function after filling form and pressing enter

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 v a2  s.  com
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