Ciao a tutti, nelle mie pagine uso uno script che mi consente di selezionare automaticamente tutti i checkbox di una colonna.
Il problema è che quando nella griglia ho due colonne con due tipologie di checkbox, io vorrei solo selezionare (tutti) i checkbox di una colonna.... ora invece vengono selezionate tutte.
Mi potete aiutare?
Grazie
codice:
<script language=JavaScript>
<!--
function confirmDelete (frm) {
// loop through all elements
for (i=0; i<frm.length; i++) {
// Look for our checkboxes only
if (frm.elements[i].name.indexOf ('DeleteThis') !=-1) {
// If any are checked then confirm alert, otherwise nothing happens
if(frm.elements[i].checked) {
return confirm ('Confermi la cancellazione?')
}
}
}
}
function select_deselectAll (chkVal, idVal) {
var frm = document.forms[0];
// loop through all elements
for (i=0; i<frm.length; i++) {
// // Look for our Header Template's Checkbox
if (idVal.indexOf ('CheckAll') != -1) {
// Check if main checkbox is checked, then select or deselect datagrid checkboxes
if(chkVal == true) {
frm.elements[i].checked = true;
} else {
frm.elements[i].checked = false;
}
// Work here with the Item Template's multiple checkboxes
} else if (idVal.indexOf('DeleteThis') != -1) {
// Check if any of the checkboxes are not checked, and then uncheck top select all checkbox
if(frm.elements[i].checked == false) {
frm.elements[1].checked = false; // Check if any of the checkboxes are not checked, and then uncheck top select all checkbox
}
}
}
}//-->
</script>
La mia è una griglia generata da .NET, vi posto comunque un esempio dell'HTML generato (se puo' servire)
Codice PHP:
<table cellspacing="0" rules="all" border="1" id="ctl00_Main_gwSpedizioni" style="width:90%;border-collapse:collapse;">
<tr style="background-color:Silver;height:20px;">
<th scope="col">
<div align="center">
<input id="ctl00_Main_gwSpedizioni_ctl01_CheckAll" type="checkbox" name="ctl00$Main$gwSpedizioni$ctl01$CheckAll" onclick="javascript: return select_deselectAll (this.checked, this.id);" />
</div>
</th>
......
</tr><tr style="height:20px;">
<td style="width:35px;">
<div align="center">
<input id="ctl00_Main_gwSpedizioni_ctl02_DeleteThis" type="checkbox" name="ctl00$Main$gwSpedizioni$ctl02$DeleteThis" />
</div>
</td>
......
<span disabled="disabled"><input id="ctl00_Main_gwSpedizioni_ctl02_chkNostroConto" type="checkbox" name="ctl00$Main$gwSpedizioni$ctl02$chkNostroConto" disabled="disabled" /></span>
</td>
</tr><tr style="background-color:#E0E0E0;height:20px;">
<td style="width:35px;">
<div align="center">
<input id="ctl00_Main_gwSpedizioni_ctl03_DeleteThis" type="checkbox" name="ctl00$Main$gwSpedizioni$ctl03$DeleteThis" />
</div>
</td><td style="width:80px;">
.......
<span disabled="disabled"><input id="ctl00_Main_gwSpedizioni_ctl03_chkNostroConto" type="checkbox" name="ctl00$Main$gwSpedizioni$ctl03$chkNostroConto" disabled="disabled" /></span>
</td>
</tr>