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.