Js creates a form element and uses submit for submission. jssubmit
Create the form and input elements in js, set the form action and method, and use submit for submission.
<Script src = "Scripts/jquery-1.7.1.js"> </script> <script type = "text/javascript"> function SubmitFormToSF () {var sfForm = document. createElement ("form"); document. body. appendChild (sfForm); var mfInputs = "text1, checkbox1, Select1, Hidden1"; var sfInputs = "text1_c, checkbox1_c, Select1_c, Hidden1_c"; var mFInputsArray = mfInputs. split (","); var sFInputsArray = sfInputs. split (","); for (I = 0; I <mFInputsArray. length; I ++) {createInput (sfForm, "text", sFInputsArray [I], GetInputValue (document. getElementById (mFInputsArray [I])} // create a contact time // create a hidden domain sfForm. method = "post"; sfForm. action = "c. aspx "; sfForm. submit ();} function createInput (sfForm, type, name, value) {var tmpInput = document. createElement ("input"); tmpInput. type = type; tmpInput. name = name; tmpInput. value = value; sfForm. appendChild (tmpInput);} function GetInputValue (EPT) {switch (EPT. type) {case "text": return EPT. value; break; case "hidden": return EPT. value; break; case "checkbox": return EPT. checked; break; case "select-one": return ipt. value; break ;}} function getContratTime () {var anytime =time ("# anytime"); var afternoon =$ ("# afternoon "); var morning = $ ("# morning"); var evening = $ ("# evening"); if (anytime. checked) {return "morning, afternoon, evening";} else {if (morning. checked) {return morning. val ();} else if (afternoon. checked) {return afternoon. val ();} else if (evening. checked) {return evening. val () ;}return "" ;}}</script>
Js submission and submit submission
Who can tell me the difference between JS and button submission forms?
A: The difference is not big. If you use <input type = "submit" name = "button"> This is a built-in button for submitting forms, it is convenient to use this button, but it has a feature that it cannot be verified when submitting a form (it can be verified by js ). While js submits forms
<Input name = "button" id = "tijiao" type = "button" value = "Submit" onclick = "XXX ()"> type = "button ", it is just a common button. To implement the form submission function, JavaScript must be used. Then xxx () is the js function implemented for it. In xxx (), document. form7.submit (); you can obtain the form submission only. The form here is form7 for submission. In fact, form7 is the current form, because name = "form7"
QQ: 58325541
How to Use js to submit forms in html
Method 1. Create two forms for submission on the same page:
<Form action = "? "Name =" form1 "id =" form1 ">
<! -- Form Content -->
<Input type = "submit"/>
</Form>
<Form action = "? "Name =" form1 "id =" form1 ">
<! -- Form Content -->
<Input type = "submit"/>
</Form>
Method 2: if there is only one form, submit it through js:
<Script type = "text/javascript" language = "javascript">
Function submitYouFrom (path ){
$('Form1 '). action = path;
$('Form1 '). submit ();
}
</Script>
<Form action = "? "Name =" form1 "id =" form1 ">
<! -- Form Content -->
<Input type = "button" value = "Submit 1" onclick = "submitYouFrom ('address 1')"/>
<Input type = "button" value = "Submit 2" onclick = "submitYouFrom ('address 2')"/>
</Form>