Jqueue values and methods for dynamically setting the Action property of form forms

Source: Internet
Author: User

head> <meta http-equiv= "Content-type" content= "text/html"; Charset=utf-8 "> <title>web Service File up&down test</title> <script type=" Text/javascript "src= "Js/jquery-1.7.js" ></script>  


The JS code above:

1. $ (function ()) function is used to dynamically modify the value of the selected file;

2, GetUrl () method for form submission, modify the value of the action;



Reproduced in addition:

#########################################

HTML code:

<form id= "Myformid" name= "MyForm" action= "" method= "POST" >
<input type= "hidden" id= "Inparam" name= "Inparam"/>
<input type= "hidden" id= "Tstype" name= "Tstype"/>
<input type= "hidden" id= "Zd" name= "Zd"/>
</form>

A friend familiar with JavaScript must know that JS can dynamically change the value of the action in form forms as follows:

Document.myForm.action = "userinfo.shtml";

Note that the form label must have the name attribute, the light has an ID, no name does not work

document.myform.attributes["Action"].value = "XXXXXXXX";

document.all ("Myformid"). setattribute ("Action", "value of the action to be assigned");

Both of these methods have been tested in JavaScript.

-------

Here's how to set the value of the action in form forms in jquery.

$ ("#myFormId"). attr ("Action", "userinfo.shtml");

"Note": $ ("#myFormId"). action= "XXX"; This kind of writing is not working!

-------------------------------------------------------------------------------------------

<form action= "xxx.php" id= "Demo_form" method= "POST" >

<input type= "text" id= "Form_stock" name= "s" data-default= "code/name/Pinyin" value= ""/>

<input type= "hidden" value= "Addstock" name= "action"/>

<button onclick= "$ (' #demo_form '). attr ({' Action ': ' insert.php '}). Submit ();" > Add </button>

<button onclick= "$ (' #demo_form '). attr ({' Action ': ' search.php '}). Submit ();" > Enquiry </button>

</form>


-------------------------------------------------------------------------------------------

When you use jquery, you can set the following:

Form form:

<form name= "MyForm" id= "MyForm" action= "ssss" "method=" Post "onsubmit=" GetUrl (); " >

JavaScript method:


<script type= "Text/javascript" >
     function GetUrl () {    
       $ (' form '). attr (' action ', ' New_url ');       
    }
 </script>

Or with simple javascript:

function Test1 () {  
   alert (document.myform.action);//return value: Http://localhost:8080/XXX/ssss
   alert ( document.myform.attributes["Action"].value)//return value: SSSs    is different from the previous line
//   below three lines,         
   whichever line document.getElementById (' MyForm '). action= ' New_url ';
   document.myform.action= ' New_url ';
   document.myform.attributes["Action"].value = ' new_url ';
}









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.