Home Javascript JavaScript submit method
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

JavaScript submit method

Advertisement
We can submit forms in following two ways in an HTML page

JavaScript submit method

     

We can submit forms in following two ways in an HTML page:

  1. By using submit button 
  2. Submitting form programmatically using JavaScript. 

In this part of JavaScript methods tutorial we are going to describe you the second way of form submission i.e. submitting form programmatically using the JavaScript method "submit()". Syntax for using the submit() method is as follows :

Syntax:

 document.formname.submit();

Where formname is the name of the form which is to be submitted.

Description of code:

To illustrate the submit() method we have created a form named "frm". When we click on the link in this form, it calls the function submitForm() defined in the <script> tags. This function at last submits the form by calling submit() method with the form element reference object and simultaneously it moves to the "SuccessPage.html" as we have defined in the action attribute of the form tag. Full HTML code is as follows :

submitExample.html

<html>
 <head>
 <title>submit() method example</title>
 <script language="JavaScript">
	function submitForm()
	{
	  alert("Going to sbmit form");
	  document.frm.submit();
	}
 </script>
</head>
<body>
 <div style="background: #ff9900; width:'100%';"
       align="center">
  <font color="#0000ff" size="12pt">
	<b>submit() Example</b>
  </font>
 </div>
  <center>
    <form name="frm" action="SuccessPage.html">
      <p>Click on the following link to submit form</p>
      <a href="javascript: submitForm();">Submit Form</a>
    </form>
  </center>
 </body>
</html>

SuccessPage.html

<html>
 <head>
   <title>Submission success page</title>
 </head>
<body>
<div style="background: #ff9900; width:'100%';"
     align="center">
  <font color="#0000ff" size="12pt">
	<b>success page</b>
  </font>
 </div>
<center>
<p>Great ! You have submitted form successfully</p>
<a href="javascript:history.go(-1);">Go Back</a>
</center>
</body>
</html>

Output:

Click on the link "Submit Form" 

It goes to the SuccessPage.html as a result to the submission of form. We can also come back to the previous page by clicking on the link "Go Back".

Download Source Code

     

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 15, 2009

Related Tutorials

Ask Questions?    Discuss: JavaScript submit method   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
akbar
December 24, 2011
known Submit method

Dear sir, mughe submit karne ka method chahiye Scripting langage agar hum submit button par click kare to vo data sotre karne ka method chahiye
DMCA.com