Get your own website Result Size: 625 x 565
x
 
<!DOCTYPE html>
<html>
<body>
<p>Use 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="/action_page.php">
  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>