hc98br
ISP
- Aug 14, 2003
- 46
I'm having problems with the included bit of code (sorry its so long, but I wanted to be clear). The code lets you create a list by clicking the button, each click adds another item and selects it, clicking an item selects it.
Works great in Netscape, but fails in IE, whilst each list item is created OK, you cannnot reference it, so I get the error 'document.getElementById(...).style' is not an object. when creating.
Surley I'm just missing somthing small, any help is greatly appricated.
Thanks
Ben.
Works great in Netscape, but fails in IE, whilst each list item is created OK, you cannnot reference it, so I get the error 'document.getElementById(...).style' is not an object. when creating.
Surley I'm just missing somthing small, any help is greatly appricated.
Thanks
Ben.
Code:
<HTML>
<INPUT TYPE="BUTTON" VALUE=" + " onClick="add();">
<DIV ID="list">
<DIV ID="row0" onClick="selectrow(0);">Item 0</DIV>
</DIV>
<SCRIPT>
function add() {
mainDivElement = document.getElementById("list");
count++;
newNote = document.createElement("div");
newNote.setAttribute("ID", "row" + count);
newNote.setAttribute("onClick", "selectrow(" + count + ");");
noteText = document.createTextNode("Item "+count);
newNote.appendChild(noteText);
mainDivElement.appendChild(newNote);
selectrow(count)
}
function selectrow(row) {
eval('document.getElementById("row' + currentSelected + '").style.backgroundColor = "";');
eval('document.getElementById("row' + row + '").style.backgroundColor = "#99DDFF";');
currentSelected = row;
}
var count = 0
var currentSelected = 0
selectrow(0)
</SCRIPT>
</BODY></HTML>