Firebug says selected is undefined. Do you know why? I want it to add the class selected to all of the tr’s in my table when the checkbox is checked. Everything else in the function works.
function selectall () {
var messages= document.getElementById('pm');
var selected= document.getElementsByTagName('tr')
var i =0;
if (checked === false)
{
checked = true;
document.getElementById('multiple_action').disabled = false;
document.getElementById('drop_button').setAttribute("class", "drop_button");
}
else
{
checked = false;
document.getElementById('multiple_action').disabled = true;
document.getElementById('drop_button').setAttribute("class", "drop_button disabled");
}
for (i; i < messages.elements.length; i++)
{
messages.elements[i].checked = checked;
selected.[i].setAttribute("class", "selected");
}
}
checked=false;
The loop that the selected items are used in, is determined by the number of form elements in the messages form.
var messages= document.getElementById('pm');
var selected= document.getElementsByTagName('tr')
...
for (i; i < messages.elements.length; i++) {
messages.elements[i].checked = checked;
selected[i].setAttribute("class", "selected");
}
How do those numbers compare? The number of elements in the messages form versus the number of tr elements on the page?
These numbers are equal. Each <tr> has a checkbox. Essentially, I am making a private messaging system and each message has a checkbox. This is the function for the select all checkbox. But I want to be able to style each tr that is selected.