When you submit the form, a function is triggered which alerts some text - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Submit

Description

When you submit the form, a function is triggered which alerts some text

Demo Code

ResultView the demo in separate window

<html>
   <head></head>
   <body> 
      <form action="demo_form.asp" onsubmit="return myFunction()">
          Enter name: /*from ww w . j av a 2  s .co m*/
         <input type="text" name="fname"> 
         <input type="submit" value="Submit"> 
      </form> 
      <script>
    function myFunction() {
        console.log("The form was submitted");
        return false;
    }
    
      </script>  
   </body>
</html>

Related Tutorials