JS Control Form Form Action whereabouts

Source: Internet
Author: User

http://blog.csdn.net/w709854369/article/details/6261624

I do not know if we have encountered this situation, when we submit a form, it may be due to different parameters to be submitted to a different action address. Then we can use JS to achieve this function.
===============
Submit the same content to a different page
===============

[JavaScript]View Plaincopy
  1. <mce:script type="Text/javascript" ><!--
  2. function Insertstu () {
  3. document.getElementById (' MyForm '). Action = "Ctl.jsp?op=insert";
  4. document.getElementById ("MyForm"). Submit ();
  5. }
  6. function Deletestu () {
  7. document.getElementById (' MyForm '). Action = "Ctl.jsp?op=delete";
  8. document.getElementById ("MyForm"). Submit ();
  9. }
  10. function Modifystu () {
  11. document.getElementById (' MyForm '). Action = "Ctl.jsp?op=modify";
  12. document.getElementById ("MyForm"). Submit ();
  13. }
  14. function Selectstu () {
  15. document.getElementById (' MyForm '). Action = "Ctl.jsp?op=select";
  16. document.getElementById ("MyForm"). Submit ();
  17. }
  18. T;</mce:script>

<form id= "MyForm" action= "" method= "POST" >

<input type= "button" Name= "Qurray" value= "Query" onclick= "Selectstu ()"/>
<input type= "button" Name= "Updata" value= "Modify" onclick= "Modifystu ()"/>
<input type= "button" value= "Add" onclick= "Insertstu ()"/>
<input type= "button" Name= "del" value= "delete" onclick= "Deletestu ()"/>

</form>

==========================================================

You can also write the JS statement directly in the onclick of the input button:

<form name= "Form1" action= "" >
<input type= "button" value= "Action1" onclick= "form1.action= ' 1 '; Form1.submit ();" >
<input type= "button" value= "Action2" onclick= "form1.action= ' 2 '; Form1.submit ();" >
</form>

JS Control Form Form Action whereabouts

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.