|
im executing the following code as an external JS file for some checkboxes. The idea is to allow the user to check 'all' without having to check each one:
// onclick="return setAllCheckboxes(this, checkboxGroupName)"
function setAllCheckboxes(ctrl, group) {
var x, len = group.length;
for(x=0; x<len; ++x) {
group[x].checked = ctrl.checked;
}
return true;
}
|
|
However, i want one of these sets of checkboxes to be selected when the user enters the page, i tried the following when calling the function but i had no success:
print("<tr><td><input type=\"checkbox\" id=\"allBox\" onload=\"return setAllCheckboxes(this, laneBox)\"
onclick=\"setAllCheckboxes(this, laneBox);\"></td><td colspan=\"$allspan\">ALL</td></tr>\n");
|
|
If anyone has any insight on how to accomplish this it would be very appreciated. I dont want to use a form name or reference any JS in the body tag, im developing a self contained function that someone else will use.
thanks in advance! :D
|
|
|
Hi,
First of all its suprising why u pass 2 parameters which are the same , i think instead of passing "this" which is same as the pbject which u are apassing as 2nd param , u pass true or false as the first paramtere and change the function as
function setAllCheckboxes(ctrl, group) {
var x, len = group.length;
for(x=0; x<len; ++x) {
group[x].checked = ctrl; // modified by Hemang
}
return true;
}
and then u can call this function onload event of body and this will work fine
|
|
|
|
|
|
|
// |