Thursday, February 10, 2011

How to Submit a Form Using JavaScript

Generally, a form is submitted when the user presses a submit button. However, sometimes, you may need to submit the form programmatically using JavaScript.
JavaScript provides the form object that contains the submit() method. Use the ‘id’ of the form to get the form object.
For example, if the name of your form is ‘myform’, the JavaScript code for the submit call is:
document.forms["myform"].submit();

But, how to identify a form? Give an id attribute in the form tag
<form id='myform' action='formmail.pl'>
Here is the 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()">Searcha>
form>
<script type="text/javascript">
function submitform()
{
  document.myform.submit();
}
script>
if you want to want to study this in brief please follow the below link:
http://www.javascript-coder.com/javascript-form/javascript-form-submit.phtml


1 comment:

  1. I have read this post. collection of post is a nice one .. That I will inform about your post to my friends and all the best for your future posts..
    Thanks

    SEO Company in India
    Internet Marketing Company in India

    ReplyDelete

Please Comment Here!

How to backup and download Database using PHP

< ?php $mysqlUserName = 'databaseusername' ; $mysqlPassword = 'databasepassword' ; $mysqlHostNa...