bhakti_thakkar
04-30-2008, 08:21 AM
Hi all,
i have an array of checkboxes and i have Check All | Uncheck All links which on click will check all or unchecks all the checkboxes.
Following is the checkbox:
<input type="checkbox" id="Item_ID[]" name="Item_ID[<?=$key?>]" <?=$checked?> value="<?=$iarr['pk']?>">
following is the link code and javascript :
<a href='' onclick="setCheckboxes(true) ; return false;"> Check All</a> <br> <a href='' onclick="setCheckboxes(false); return false;"> Uncheck All</a>
<script language="javascript">
function setCheckboxes(do_check)
{
var elts= document.getElementById('Item_ID[]');
// alert(elts);
elts_cnt = elts.length;
// alert(elts_cnt);
if (elts_cnt>0) {
for (var i = 0; i < elts_cnt; i++) {
elts[i].checked = do_check;
} // end for
} else {
elts.checked = do_check;
} // end if... else
return true;
} // end of the 'setCheckboxes()' function
</script>
But the above script doesnt work in Opera :confused:. it works fine in IE. how can i modify the script to make it work in all the browsers. i cannot change the name or id of the checkboxes.
Thanks in advance
i have an array of checkboxes and i have Check All | Uncheck All links which on click will check all or unchecks all the checkboxes.
Following is the checkbox:
<input type="checkbox" id="Item_ID[]" name="Item_ID[<?=$key?>]" <?=$checked?> value="<?=$iarr['pk']?>">
following is the link code and javascript :
<a href='' onclick="setCheckboxes(true) ; return false;"> Check All</a> <br> <a href='' onclick="setCheckboxes(false); return false;"> Uncheck All</a>
<script language="javascript">
function setCheckboxes(do_check)
{
var elts= document.getElementById('Item_ID[]');
// alert(elts);
elts_cnt = elts.length;
// alert(elts_cnt);
if (elts_cnt>0) {
for (var i = 0; i < elts_cnt; i++) {
elts[i].checked = do_check;
} // end for
} else {
elts.checked = do_check;
} // end if... else
return true;
} // end of the 'setCheckboxes()' function
</script>
But the above script doesnt work in Opera :confused:. it works fine in IE. how can i modify the script to make it work in all the browsers. i cannot change the name or id of the checkboxes.
Thanks in advance