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="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>
</html>


Result:
Try it Yourself - © w3schools.com
Privacy Policy