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.getElementById(tableID);
if((document.getElementById('select_degree').style.visibility = 'hidden')&&(document.getElementById('select_degree')!=null)){
document.getElementById('select_degree').style.visibility = 'visible';
document.getElementById('select_ratings').style.visibility = 'visible';
}
else{
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;
}
}
}
When document.getelementById('add_degree') is null I get the error:
document.getElementById("select_degree") is null
addRow(tableID="add_degree")
But I already have a else statement if the element is null
document.getElementById('select_degree')isnull, thendocument.getElementById('select_degree').style.visibilitywill throw an error. If an error is thrown the whole script will terminate, theelsebranch will never be executed. Reverse the conditions. First check whether the element exists, and then assign (or compare) the other value. Does not make much sense to do it the other way round.