Use js to submit a form to solve the problem that a page has multiple submit buttons. js form

Source: Internet
Author: User

Use js to submit a form to solve the problem that a page has multiple submit buttons. js form

Using js to submit a form solves the problem of multiple submit buttons on a page, mainly to determine whether the text is submitted and then execute the corresponding action, which is relatively simple.

<Pre class = "javascript" name = "code"> function check (txt) {$ j ("form "). submit (function () {if ($ txt = "submit") {this. action = "doAddMessage. action? Button = submit "; this. submit ();} else {this. action =" doAddMessage. action? Button = save "; this. submit ();}});} </pre> <br> <input type = "IMAGE" src = "style/blue/images/button/send.png" name = "button" value = "Submit" onclick =" check (this) "/> <input type =" IMAGE "src =" style/blue/images/button/saveToDraftBox.png "name =" button "value =" save "onclick =" check (this) "/> <pre> </pre> <p> <br> for example, two image buttons are submitted on the page. At this time, we can bind an onclick event to both of them, in this case, we use jquery's form to have an event called submit. </P> <p> because dwr is used in my project, I transfer the control of jquery to dwr, and jquery re-specifies a $ j. We get the form, then, use the submit event to determine the value of the value, so that you can jump to multiple pages. </P>

Multiple submission buttons in a form

Use JS to change the button submission page: <script type = "text/javascript">
Function fun () {document. myform. action = "path to be submitted ";}
</Script> <form name = "myform">
<Input type = "button" value = "Submit" onclick = "fun ()"/>
</Form>
 
How does one solve the problem of submitting two buttons to different pages in a form? Note: Two submissions are required (because both must change data in real time)

Write two different event buttons and pass different parameters. Then, the background accepts the judgment and goes to function selectOrder (){
Document. forms (0). action = "/path" document. forms (0). submit ();}

Related Article

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.