We all know that we use a variety of input forms when submitting form. But not every type of input form is very simple to get in the document.getElementById way. Some combinations of the form are similar to checkbox or radio or select how do we get and get the submitted arguments in the server with JavaScript? More useless, on the code:
Jsp-html Code:
Copy Code code as follows:
<form action= "input.do" name= "FORMKK" >
<table>
<tbody>
<tr>
<td>text:</td>
<td>
<input type= "text" name= "text" >
</td>
</tr>
<tr>
<td>password:</td>
<td>
<input type= "password" name= "pass" >
</td>
</tr>
<tr>
<td>radio:</td>
<td>
<input type= "Radio" name= "Xingbie" value= "1" >
Man
<input type= "Radio" name= "Xingbie" value= "2" >
Woman
</td>
</tr>
<tr>
<td>checkbox:</td>
<td>
Soccer: <input type= "checkbox" name= "Hobby" value= "1"/>
Basketball: <input type= "checkbox" name= "Hobby" value= "2"/>
Bounce: <input type= "checkbox" name= "Hobby" value= "3"/>
Dou Ball: <input type= "checkbox" name= "Hobby" value= "4"/>
</td>
</tr>
<tr>
<td>hidden:</td>
<td>
<input type= "hidden" value= "123" name= "hidden"/>
</td>
</tr>
<tr>
<td>option:</td>
<td>
<select name= "opt" id= "opt" >
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
</td>
</tbody>
</table>
<input type= "button" value= "Submit" onclick= "Javascript:check ()"/>
</form>
Javascript:
Copy Code code as follows:
function Check () {
var radio = Document.getelementsbyname ("Xingbie");
var checkbox = Document.getelementsbyname ("hobby");
var select = document.getElementById ("opt");
Get Select Label
var index = Select.selectedindex;
var text = Select.options[index].text;
var value = Select.options[index].value;
Get Radio Label
for (Var i=0;i<xingbie.length;i++) {
if (Xingbie.item (i). Checked) {
var val = Xingbie.item (i). getattribute ("value");
Break
}
Continue
}
Get CheckBox Label
for (Var i=0;iif (hobbys[i].checked) {
alert (Hobbys[i].value);
}
Continue
}
Submit Form Form
Document.formkk.submit ();
}
Java:
Copy Code code as follows:
string[] Hobbys = request.getparametervalues ("hobby"); CheckBox
String Text = request.getparameter ("text"); Text
String Password = request.getparameter ("password"); Password
String Xingbie = Request.getparameter ("Xingbie"); Radio
Request.getparameter ("hidden");
Request.getparameter ("opt"); Select