Hey Guys in the below code every time the if statement is executed no matter what the condition is.
function addRow(tableID) {
var table = document.
Your if statement is not using the correct operator. Replace your =
(used for assignment) with the comparison operator: ==
. In addition, you must check if the element exists before attempting to check it's properties. If you don't, you'll get an exception when the element doesn't exist.
Here is your code, corrected and cleaned up:
function addRow(tableID) {
var objSelectDegree = document.getElementById('select_degree');
if (objSelectDegree != null && objSelectDegree.style.visibility == 'hidden') {
objSelectDegree.style.visibility = 'visible';
document.getElementById('select_ratings').style.visibility = 'visible';
}
else {
// Moved table var to else block - it was not used unless else was hit
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
var new_row = table.rows[rowCount - 1];
var row = table.insertRow(rowCount);
var colCount = table.rows[0].cells.length;
for (var i = 0; i < colCount; i++) {
var newcell = row.insertCell(i);
newcell.innerHTML = new_row.cells[i].innerHTML;
}
}
}