In general, a HTML form is created with a submit button. The user will press the button to submit a form. However, you may want to submit form by using Javascript.

The submit() method is provided for a form object in Javascript that it is the same as clicking on Submit button. All major browsers support the submit() method.

Example Codes

In this example, the form name is ‘testform’. When the hyperlink “Submit” is clicked, the function submitform() is called. In the function, the method submit() is called. The form name ‘testform’ should be replaced as the form name you defined.

Here is the code to submit a form when a hyperlink Submit is clicked:

[html]
<form name="testform">Search: <input type="text" name="data" />
<a onclick="submitform()">Submit</a>
</form>
<script type="text/javascript">
function submitform()
{
document.testform.submit();
}
></script>[/html]