JavaScript: How to Submit a Form When a Button is Clicked

Submitting a form can be accomplished with JavaScript by accessing the named form and then calling the submit method on it.

<form name="frmTest" action="somepage.html”" method="post">
First Name: <input type=
"text" name="FirstName">
<input type=
"button" onclick="document.frmTest.submit();" value="Submit Form">
</form>

The JavaScript occurs with the onclick attribute of the button input type. It uses the document object model to access the named form and calls the submit method on it.

One Response to “JavaScript: How to Submit a Form When a Button is Clicked”

  1. Using the button method above, how do I pass a value

Leave a Reply