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:
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