In general a form gets submitted when the user clicks on the submit button. But sometimes we may require to programatically submit the form using Javascript.
If the name of your form is ‘myform’, the JavaScript code for the submit call is:
If the name of your form is ‘myform’, the JavaScript code for the submit call is:
document.forms["myform"].submit();
Here is a simple code to submit a form when a hyperlink is clicked:
<form name="myform" action="handle-data.php">
Search: <input type='text' name='query' />
<a href="javascript: submitform()">Search</a>
</form>
<script type="text/javascript">
function submitform()
{
document.myform.submit();
}
</script>
Search: <input type='text' name='query' />
<a href="javascript: submitform()">Search</a>
</form>
<script type="text/javascript">
function submitform()
{
document.myform.submit();
}
</script>