Archive for June 23, 2007

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

Posted in JavaScript, Software, Web, internet, programming on June 23, 2007 by Joey

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.