Javascript method is not working on Firefox
Merand’s Question:
My stylesheet is working on ie, however it isnt working on firefox. It gives an error such as:
InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable @
TypeError: document.getElementById(…) is null.
Here is my code:
<script style="javascript">
function displayRevision2() {
for (i = 1; i & lt; j; i++) {
foo = document.getElementById('row' + i).innerHTML;
substring = foo.substr(0, foo.search("n") - 1);
//displayRevision(substring);
if (flag == 1) document.getElementById(substring).style.display = "";
else document.getElementById(substring).style.display = "none";
}
if (flag == 1) flag = 0;
else flag = 1;
}
</script>
<script style="javascript">
function dispTD(num) {
rowtxt = '<TD class="br" align="middle" id="row' + num + '">';
document.write(rowtxt);
}
</script>
<script style="javascript">
function dispEndTD() {
document.write("</TD>");
}
</script>
It may be because the element the script is searching for does not exist on the document. Try to check if the scripts finds the element first before directly accessing its attributes.
fooElement = document.getElementById('row' + i);
if(fooElement) foo = fooElement.innerHTML;