Detailed Explanation of Usage of checkbox in jsp

  • 2021-08-12 03:16:53
  • OfStack


String[] picked = request.getParameterValues("open");
  if (picked != null) {
   for (int i = 0;i < picked.length; i++) {
  // System.out.println("11"+picked[i]);
   uDao.getCheckOpen( picked[i]); 
   } 
  }

Today, I used checkbox with fear, which I thought was quite mysterious, but when you decided to calm down and get it done, you found that things were far less difficult than imagined O (φ _ φ) O ~

*****************************************************************************************************

Theories from the Internet:

(Gets the value in checkbox)


String[] picked = request.getParameterValues("colname");
String[] a=new String[20];
 if (picked != null) {
  for (int i = 0;i < picked.length; i++) {
   out.println(" "+picked[i]);
 } else {
   out.println ("none");
 }

How to realize all selection on jsp page checkbox.

Use javascript.


<html> 
<body> 
<script> 
function kk(){ 
var handleEl = document.getElementById("kkHandler"); 
var els = document.getElementsByName("kk"); 
for(i=0;i<els.length;i++){ 
els[i].checked = handleEl.checked; 
} 
 
} 
</script> 
<input type=checkbox onclick="kk()" name="kkHandler"> All selection <br> 
<input type=checkbox name="kk"> 
<input type=checkbox name="kk"> 
</body> 
</html>

2:


<form name="form" ID="Form1"> 
<input type="checkbox" name="id" value="" ID="Checkbox1">1 
<input type="checkbox" name="id" value="" ID="Checkbox2">2 
<input type="checkbox" name="chose" value="" onclick="selectAll()" ID="Checkbox5">allselect 
</form> 
<script> 
function selectAll() 
{ 
if(!document.form.id.length){ 
 if(document.form.chose.checked){ 
  document.form.id.checked=true; 
 } 
 else{ 
  document.form.id.checked=false; 
 } 
} 
else{ 
 for(var i=0;i<document.form.id.length;i++){ 
  if(document.form.chose.checked){ 
  document.form.id[i].checked=true; 
  } 
  else{ 
  document.form.id[i].checked=false; 
  } 
 } 
}    
} 
</script>

******************************************************************************************************

My code

jsp page code:


<script LANGUAGE = "javaScript">
<!--
 function selectAll() 
 { 
 if(!document.form.open.length){ 
  if(document.form.chose.checked){ 
   document.form.open.checked=true; 
  } 
  else{ 
   document.form.open.checked=false; 
  } 
 } 
 else{ 
  for(var i=0;i<document.form.open.length;i++){ 
   if(document.form.chose.checked){ 
   document.form.open[i].checked=true; 
   } 
   else{ 
   document.form.open[i].checked=false; 
   } 
  } 
 }    
}
-->
</script>

<logic:present name="Infor">
 <logic:iterate id="show" name="Infor">
 <tr bgcolor = '#E7F1FE'>
 <td width="5%">
 <logic:equal value=" Not opened " name="show" property="status">
  <input type="checkbox" name="open" value="<bean:write name="show" property="legalPersonCode" />">
 </logic:equal>

The writing in action:

String[] picked = request.getParameterValues("open");
if (picked != null) {
for (int i = 0;i < picked.length; i++) {
// System.out.println("11"+picked[i]);
uDao.getCheckOpen( picked[i]);
}
}


Related articles: