I'm dynamically generating a table in my hta and I want to have the line which has been clicked highlight. I can set the onClick for each row to call a function which does the highlighting but the problem is, I don't know how to identify which row called it.
eg oRow.onClick = HighlightRow(Row Number)
in HighlightRow: document.getelementbyid(sTable).rows(Row Number).style.backgroundcolor = "yellow"
I thought about having IDs for each row but the table needs to remain dynamic as the user will be adding and removing rows. Any thoughts?
Hmm, on further investigation it appears I can't seem to set the onclick for the row the way I want to....
Setting the onclick for the row/cell using HTML tags is fine but I'd really like generate the table without having to set the innerhtml of the div using sHTML = sHTML & "<TD onclick=""onTDClick( Me )"">" I've been adding my rows/cells dynamically using something like this:
Set oRow = document.createElement("TR") oTBody.appendChild(oRow) set oCell = document.createElement("TD") oRow.appendChild(oCell)
I thought I should be able to set the onclick properties before using appendChild by: oCell.onClick = mySubroutine(sMyArgument)
or later by: myCellID.onclick = mySubroutine(sMyArgument)
Neither of these work - can anyone tell me why and how I can do this?
Aha - I've found a way to do it with vbscript....! Although you can't pass parameters with getref, you can find out what triggered it using the event object (window.event).
The onclick event is assigned when the row is generated by:
oRow.onclick = getref("RowClicked")
Then the element which caused the event can bereferenced in RowClicked using:
window.event.srcElement
However.... This by itself actually references the cell not the row - so I stuck in an extra bit to work my way up to the row:
Dim oThisElement Set oThisElement = window.event.srcElement Do Until oThisElement.tagName = "TR" Set oThisElement = oThisElement.parentElement Loop
I did it as a loop not just a single step up because some of my cells contain elements so if they are clicked on then I'd have to go up two levels etc.
I did appreciate your JScript answer (put me on the right track for finding the vbscript way) - just was limited to using vbscript only (my boss's requirement)