From form submitter

Source: Internet
Author: User

I. Requirements:

Idea: Document. Form. Action. The form is submitted in different directions, and the form is submitted in JavaScript.
The same form can be submitted to different background processing programs based on user selection. That is, the submitter of the form. For example, when writing Forum programs, if you want to implement both the sending and submission function and the preview function when sending posts, you will encounter the above problems. That is, when you click the submit button, we want the form to be submitted to the "Submit" handler. When you click the preview button, we want the form to be submitted to the "preview" handler. So how can we implement the above functions? The following code can solve this problem.

Ii. test form

1 <form name = "form" method = "Post"> 2 comments: <input name = "test"> <br> 3 <input type = "button" value = "Submit" onclick = Send ()> 4 <input type = "button" value = "preview" onclick = Preview ()> 5 </form>
View code

Iii. submitter JS Code of forms

 

 1 <script language=javascript> 2 function send() 3   { 4     document.form.action="send.asp" 5     document.form.submit() 6    } 7 function preview() 8    { 9      document.form.action="preview.asp"10      document.form.submit()11    }12 </script>
View code

 

4. Notes

 

Two notes about the above instance:
1. In the entire form, there should be no tag named action or submit. Otherwise, an error "the object does not support this attribute and method" will occur. For example, the code "<input type = 'xxxx' name = 'action'>" cannot appear in the form;
2. The name attribute should exist in the form tag. That is, a name should be given to the form. In the statements document. Form. Action and document. Form. Submit, "form" is the form name.
The form is not only used in the Forum program, but also in many scenarios. The proper use of the form's forward submission function can greatly enhance the humanization of the website.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.