How to submit form using Javascript?




If HTML form have the attributes method="post" and action="someprocess.php", and in the form if there is button like,
<input type="submit" value="submit"> , then form will get submitted on that button click.

But if we want to submit the form on any link i.e <a>  tag or any event other than submit button, then we have to use javascript.

How ?
 See,
Here is the code to submit a form when a hyperlink is clicked:

<form name="myform" action="process.php">
Text Field: <input type='text' name='text1' />
<a href="javascript: submitform()">Search</a>
</form>

<script type="text/javascript">
function submitform()
{
  document.myform.submit();
}
</script>


Javascript submit is same as HTML submit.
You can submit form on events like: onChange, onClick,....etc.

I think its enough to understand the concept.

I would like to hear from you...!!!


No comments:

Post a Comment

We are here to listen you, Comment your valueable opinion...!!!