In some cases, the same form in different cases submitted to different processing actions, you can dynamically change the properties of the form in JS, meet the different conditions of form submission needs.
Such as:
Copy Code code as follows:
<form id= "form" name= "form" method= "POST" enctype= "Multipart/form-data" action= "action1.jsp" target= "iframe" >
<input type= "File" name= "file" id= "file" class= "Input_text80" ></input>
<input id= "name" name= "name"/>
<input type= "button" value= "updated to probe point" onclick= "Javascript:formsubmit ();" ></input>
</form>
<iframe name= "iframe" ></iframe>
Now requires condition 1 to be submitted in the way above, to method= "POST" enctype= "Multipart/form-data" action= "action1.jsp" target= "iframe" Submit to action1.jsp for processing, condition 2 to submit to action2.jsp processing in normal text, and open new page. You need to dynamically change the properties of the form through JS:
Copy Code code as follows:
function Formsubmit () {
if (flag== "1") {
$ ("#form"). Submit ();
}else if (flag== "2") {
$ ("#form"). attr ("Action", "deployresult.jsp");
$ ("#form"). attr ("target", "_blank");
$ ("#form"). attr ("Method", "get");
$ ("#form"). attr ("Enctype", "application/x-www-form-urlencoded");
$ ("#form"). attr ("Encoding", "application/x-www-form-urlencoded");
$ ("#form"). Submit ();
}
}
Note:
When changing the Enctype property of a form, write $ ("#form") only. attr ("Enctype", "application/x-www-form-urlencoded");
Will not work, the following two sentences must be combined to take effect:
Copy Code code as follows:
$ ("#form"). attr ("Enctype", "application/x-www-form-urlencoded");
$ ("#form"). attr ("Encoding", "application/x-www-form-urlencoded");
Where Enctype's attribute value meaning refers to the enctype properties of HTML <form> tags