Select All or invert settings for the checkbox in the list, and select all for the checkbox
Select all settings for checkbox selection in the list
1
The above code mainly handles
1. If a row is selected in the list, the checkbox of the row is selected. If you click it again, the checkbox is deselected.
2. The list contains all selected checkboxes.
The following is a piece of code I have added:
1 ... 2 <input id="allid" type="checkbox" onclick="selectAll()"/> 3 4 <s:iterator value="page.records"> 5 <td style="CURSOR: hand; HEIGHT: 30px" align="center" width="2%"> 6 <input class="select" type="checkbox" name="selectList" value="${id}"/> 7 </td> 8 ... 9 10 11 function selectAll() {12 var allche = document.getElementById("allid"); 13 var che = document.getElementsByName("selectList"); 14 if(allche.checked == true){ 15 for(var i=0;i<che.length;i++){ 16 if(che[i].checked==true){17 che[i].checked=false;18 }19 else{20 che[i].checked="checked";21 }22 } 23 }else{ 24 for(var i=0;i<che.length;i++){ 25 if(che[i].checked==true){26 che[i].checked=false; 27 }28 else29 {30 che[i].checked="checked";31 }32 33 } 34 } 35 }