Tryit Editor v2.3

Edit This Code:
<!DOCTYPE html> <html> <body> <p>This example uses the HTML DOM to assign an "onsubmit" event to a form element.</p> <p>When you submit the form, a function is triggered which alerts some text.</p> <form id="myForm" action="http://www.w3schools.com/jsref/demo_form.asp"> Enter name: <input type="text" name="fname"> <input type="submit" value="Submit"> </form> <script> document.getElementById("myForm").onsubmit = function() {myFunction()}; function myFunction() { alert("The form was submitted"); } </script> </body> <!-- Mirrored from www.w3schools.com/jsref/tryit.asp?filename=tryjsref_onsubmit_dom by HTTrack Website Copier/3.x [XR&CO'2014], Fri, 23 Jan 2015 08:29:54 GMT --> </html>
Result:
Try it Yourself - © w3schools.com