This article is mainly about JavaScript and Java access to a variety of form form information simple examples are introduced, need friends can come to the reference, I hope to help you.
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: Code as follows: <form action= "input.do" name= "FORMKK" > <table> <tbody> <tr> <td>text:</td> <td> &NBS P <input type= "text" name= "text" > </td> </tr> &NBSP ; <tr> <td>password:</td> <td> <input type= "password" name= "pass" > </td> , </tr> & nbsp <tr> <td>radio:</td> <td> &NB Sp <input type= "Radio" name= "Xingbie" value= "1"> man <input type= "Radio" name= "Xingbie" value= "2" > &N Bsp women </td> </tr> <tr> &NBS P <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" /> & nbsp Bucket ball: <input type= "checkbox" name= "Hobby" value= "4" /> </td> &NBS p;</tr> <tr> <td>hidden:</td> <T d> <input type= "hidden" value= "123" name= "hidden"/> , </td> & nbsp </tr> <tr> <td>option:</td> <TD&G T <select name= "opt" id= "opt" > <option>1</option> <option>2</option> <option>3</option> & nbsp <option>4</option> </select> </td> </tbody> </table> <input type= "button" value= " Submit "onclick=" Javascript:check () "/> </form> javascript: Code as follows: 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; //Get radio tag for (var i=0;i<xingbie.length;i++) { if (Xingbie.item (i). Checked) { var val = Xingbie.item (i). getattribute ("value"); break; } continue; &NBSP} //get CheckBox label for (var i=0;i<hobbys.length;i++) { if (hobbys[i) . checked) { alert (hobbys[i].value); } continue; &NBSP //submit form document.formkk.submit (); } Java: 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