Javascript DOM HTML Form submit() Method

Introduction

Submit a form:

document.getElementById("myForm").submit();

View in separate window

<!DOCTYPE html>
<html>
<body>
<form id="myForm" action="/action_page.php">
  First name: <input type="text" name="fname"><br>
  Last name: <input type="text" name="lname"><br><br>
  <input type="button" onclick="myFunction()" value="Submit form">
</form>//from w w w. j  a va 2 s.c  o  m

<script>
function myFunction() {
  document.getElementById("myForm").submit();
}
</script>

</body>
</html>

The submit() method submits the form.

It is the same as clicking the Submit button.




PreviousNext

Related