<html>
<body>
<p>Use the addEventListener() method to attach a "submit" 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").addEventListener("submit", myFunction);
function myFunction() {
alert("The form was submitted");
}
</script>
</body>
</html>