Home > Web Front-end > JS Tutorial > body text

Simple examples of Javascript and Java obtaining various form information_javascript skills

WBOY
Release: 2016-05-16 16:59:56
Original
1158 people have browsed it

Everyone knows that we use a variety of input forms when submitting forms. But not every input form can be easily obtained using Document.getElementById. There are some combined forms similar to checkbox or radio or select. How do we use javascript to obtain and obtain the submitted parameters in the server? It is useless to say more, here is the code:

Jsp-html code:

Copy code The code is as follows:







                                                                                     
Male

Female
                                                                                              Football:
Basketball:
Shooting:
Douqiu:
                                                                                      



text:
>                                                                                                                
option:< /td>
                                                                                                                                                                                               option>

< /tbody>






Javascript:





Copy code


The code is as follows:

function check(){

   var radio = document.getElementsByName("xingbie");
   var checkbox = document.getElementsByName("hobby");
   var select = document.getElementById("opt");

   //获取select标签
   var index = select.selectedIndex;
   var text = select.options[index].text;
   var value = select.options[index].value;

   //获取radio标签
   for(var i=0;i    if(xingbie.item(i).checked){
     var val = xingbie.item(i).getAttribute("value");
     break;
    }
    continue;
   }
   //获取checkbox标签
   for(var i=0;i    if(hobbys[i].checked){
     alert(hobbys[i].value);
    }
    continue;
   }

   //提交form表单
   document.formkk.submit();

   
  }

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");
 request.getParameter("opt");    //select
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template