FLC
11-25-2004, 03:00 AM
somewhere in the body tag I have this coding
<input type="hidden" name="hiddenName_#ContractList.ContractID#" value="#Description#" />
<input type="checkbox" name="contracts" value="#ContractList.ContractID#" />
the variable #ContractList.ContractID# comes from a query in coldfusion
and I have a header checkbox that trigger checkall() function
and the code of the function is
function checkAll()
{
var contractBoxes = document.ContractForm.contracts;
for (var i = 0; i < contractBoxes.length; ++i)
{
if (contractBoxes[i].checked == true)
{
contractBoxes[i].checked = false;
}
else
{
contractBoxes[i].checked = true;
}
}
}
the document.ContractForm.contracts; refer to a input form and contracts is a checkbox name
my problem is,
if there is only 1 row of record, the contractBoxes.length will become undefined and will not go into the for loop
if I force it by doing this
function checkAll()
{
var contractBoxes = document.ContractForm.contracts;
if (contractBoxes.length == null)
{
contractBoxes.length = 1;
}
for (var i = 0; i < contractBoxes.length; ++i)
{
if (contractBoxes[i].checked == true)
{
contractBoxes[i].checked = false;
}
else
{
contractBoxes[i].checked = true;
}
}
}
it goes into the for loop but it does not toggle my checkbox
just imagine this scenario with yahoo mailbox where there is a checkbox at the left side, you click the header checkbox, all the checkboxes will be checked,
<input type="hidden" name="hiddenName_#ContractList.ContractID#" value="#Description#" />
<input type="checkbox" name="contracts" value="#ContractList.ContractID#" />
the variable #ContractList.ContractID# comes from a query in coldfusion
and I have a header checkbox that trigger checkall() function
and the code of the function is
function checkAll()
{
var contractBoxes = document.ContractForm.contracts;
for (var i = 0; i < contractBoxes.length; ++i)
{
if (contractBoxes[i].checked == true)
{
contractBoxes[i].checked = false;
}
else
{
contractBoxes[i].checked = true;
}
}
}
the document.ContractForm.contracts; refer to a input form and contracts is a checkbox name
my problem is,
if there is only 1 row of record, the contractBoxes.length will become undefined and will not go into the for loop
if I force it by doing this
function checkAll()
{
var contractBoxes = document.ContractForm.contracts;
if (contractBoxes.length == null)
{
contractBoxes.length = 1;
}
for (var i = 0; i < contractBoxes.length; ++i)
{
if (contractBoxes[i].checked == true)
{
contractBoxes[i].checked = false;
}
else
{
contractBoxes[i].checked = true;
}
}
}
it goes into the for loop but it does not toggle my checkbox
just imagine this scenario with yahoo mailbox where there is a checkbox at the left side, you click the header checkbox, all the checkboxes will be checked,