M
Michael Champagne
We have an application to where you can select/deselect all checkboxes
in a checkbox array by clicking a 'master' checkbox at the top of the
screen. This seems to work fine unless there is only one checkbox
(these are dynamically generated). Why does this fail? If I do an
alert(field_to_check.length) with 1 element in the array like this I
get 'Undefined'. Is this because this datatype is not an array if
there is only 1 element here? Thanks for any responses.
The function that checks the checkboxes is:
function check(this_field, field_to_check)
{
var i;
if (eval(this_field.checked))
{
for(i=0; i<field_to_check.length;i++)
field_to_check.checked=true;
return 1;
}
else
{
for(i=0; i<field_to_check.length;i++)
field_to_check.checked=false;
return 0;
}
}
The onClick event to this function is:
<input type='checkbox' name='check_all' value=1 checked
onClick="check(this,
this.form.elements['acct_num_list[]']);">
And the array of checkboxes when there is 1 element in them is:
<input class='copy' type='checkbox' name="acct_num_list[]"
value='something' checked>
Mike
in a checkbox array by clicking a 'master' checkbox at the top of the
screen. This seems to work fine unless there is only one checkbox
(these are dynamically generated). Why does this fail? If I do an
alert(field_to_check.length) with 1 element in the array like this I
get 'Undefined'. Is this because this datatype is not an array if
there is only 1 element here? Thanks for any responses.
The function that checks the checkboxes is:
function check(this_field, field_to_check)
{
var i;
if (eval(this_field.checked))
{
for(i=0; i<field_to_check.length;i++)
field_to_check.checked=true;
return 1;
}
else
{
for(i=0; i<field_to_check.length;i++)
field_to_check.checked=false;
return 0;
}
}
The onClick event to this function is:
<input type='checkbox' name='check_all' value=1 checked
onClick="check(this,
this.form.elements['acct_num_list[]']);">
And the array of checkboxes when there is 1 element in them is:
<input class='copy' type='checkbox' name="acct_num_list[]"
value='something' checked>
Mike