Stop the page refreshing when enter is pressed in a form input element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Text

Description

Stop the page refreshing when enter is pressed in a form input element

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body> 
      <form id="someForm" action="" method="post" onsubmit="postText();return false"> 
         <input type="text" id="demoText"> 
         <button type="submit" id="postBtn">Post</button> 
      </form> 
      <script type="text/javascript">
 function postText() {/*from w  w w .  ja v  a  2 s.c  om*/
     console.log("Random Function...");
 }

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

Related Tutorials