I have a table with an onclick function on it. When clicked upon I get the following error:
Uncaught TypeError: Cannot set property 'className' of undefined
The strange thing is that 3 out of 5 rows the class is changed, but 2/5 are not. When clicked again on the row, one of the remaining two is changed and when clicked again the last one is changed. Here's my code:
HTML table
<tr class='invoice-tr-standard row5' onClick="FormTRClick(event, '6', '5')"><td><input type='checkbox' name='strFormFactuur[]' value='19500' id='chk6'> <img src='../images/link.png' border='0'></td>
<td><img src='../images/b_save.png' border='0' height='13px' style='cursor: pointer;' onClick="saveData('6', '?iID=19500&bType=0', 'all');")> <input type='image' src='../images/toevoegen.png' border='0' style='float: right; cursor: pointer;' name='FormDupliceer' value='19500'></td>
</tr>
<tr class='invoice-tr-standard row5' onClick="FormTRClick(event, '7', '5')"><td></td>
<td><img src='../images/b_save.png' border='0' height='13px' style='cursor: pointer;' onClick="saveData('7', '?iID=36&bType=1', 'fltBedrag');"> <input type='image' src='../images/b_delete.png' border='0' style='float: right; cursor: pointer;' name='FormVerwijder' value='36'></td>
</tr>
<tr class='invoice-tr-standard row5' onClick="FormTRClick(event, '8', '5')"><td></td>
<td><img src='../images/b_save.png' border='0' height='13px' style='cursor: pointer;' onClick="saveData('8', '?iID=37&bType=1', 'fltBedrag');"> <input type='image' src='../images/b_delete.png' border='0' style='float: right; cursor: pointer;' name='FormVerwijder' value='37'></td>
</tr>
<tr class='invoice-tr-standard row5' onClick="FormTRClick(event, '9', '5')"><td></td>
<td><img src='../images/b_save.png' border='0' height='13px' style='cursor: pointer;' onClick="saveData('9', '?iID=38&bType=1', 'fltBedrag');"> <input type='image' src='../images/b_delete.png' border='0' style='float: right; cursor: pointer;' name='FormVerwijder' value='38'></td>
</tr>
<tr class='invoice-tr-standard row5' onClick="FormTRClick(event, '10', '5')"><td></td>
<td><img src='../images/b_save.png' border='0' height='13px' style='cursor: pointer;' onClick="saveData('10', '?iID=66&bType=1', 'fltBedrag');"> <input type='image' src='../images/b_delete.png' border='0' style='float: right; cursor: pointer;' name='FormVerwijder' value='66'></td>
</tr>
The javascript function FormTRClick():
function FormTRClick(event, uID, PCID) {
var Object= event.target.tagName;
if (Object == 'TD') {
var Elements = document.getElementsByClassName('row' + PCID);
var iNumElements = Elements.length;
alert(iNumElements); // Outputs 5 as expected
for (var i=0; i < iNumElements; i++) {
Elements[i].className = "invoice-tr-clicked"; // Only changes 3 out of 5 on the first click
}
}
}
Update
When using the following Elements[i].className += " invoice-tr-clicked"; instead of Elements[i].className = "invoice-tr-clicked";, the script works as it should. But when replacing (hence the =) I get the Cannot set property 'className' of undefined error.