Horje

How to Execute a JavaScript when a form is submitted - HTML onsubmit Attribute

When you submit the form, a function is triggered which alerts some text.
index.html
Example: HTML
<!DOCTYPE html>
<html>
<body>

<p>When you submit the form, a function is triggered which alerts some text.</p>

<form action="/action_page.php" onsubmit="myFunction()">
  Enter name: <input type="text" name="fname">
  <input type="submit" value="Submit">
</form>

<script>
function myFunction() {
  alert("The form was submitted");
}
</script>

</body>
</html>

Output should be:

How to Execute a JavaScript when a form is submitted - HTML onsubmit Attribute




Type:
html
Category:
Web Tutorial
Sub Category:
HTML Attribute
Uploaded by:
Admin