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?
Say more useless, on the code:
Jsp-html Code:
<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>rad io:</td> <td> <input type= "Radio" name= "Xingbie" value= "1" > Male <input type= "Radio" name= "Xin" Gbie "value=" 2 "> Women </td> </tr> <tr> <td>checkbox:</td> <td> soccer: <i Nput type= "checkbox" name= "Hobby" value= "1"/> basketball: <input type= "checkbox" name= "Hobby" value= "2"/> Bounce ball: <i Nput type= "checkbox" name= "Hobby" value= "3"/> Bucket ball: <input type= "checkbox" name= "Hobby" value= "4"/> </td>
; </tr> <tr> <td>hidden:</td> <td> <input type= "hidden" value= "123" Name= "hidden"/&
Gt
</td> </tr> <tr> <td>option:</td> <td> <select name= "opt" id= "opt" > <OPTION&G
t;1</option> <option>2</option> <option>3</option> <option>4</option> </select> </td> </tbody> </table> <input type= "button" value= "Submit" onclick= "Javasc Ript:check () "/> </form>
Javascript:
function Check () {
var radio = document.getelementsbyname ("Xingbie");
var checkbox = Document.getelementsbyname ("hobby");
var select = document.getElementById ("opt");
Get select Tag
var index = select.selectedindex;
var text = Select.options[index].text;
var value = Select.options[index].value;
Gets the radio label for
(Var i=0;i<xingbie.length;i++) {
if (Xingbie.item (i). checked) {
var val = Xingbie.item (i). getattribute ("value");
break;
Continue;
}
Gets the checkbox label for
(Var i=0;i
Java:
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");
The above is a small series for you to bring the form element value to obtain the way JS and Java way of a simple example of all content, I hope that we support cloud Habitat Community ~