Forum Moderators: open
Does anybody have any clue, why can't I get the target id for a tr element? I use the same code for an input element, and it works fine. Here is the code.
If you click on the checkbox, it will alert it's id, and eventBubbling has cancelled, so no other handler starts - that is fine.
BUT, when you click on the "Simple cell", The alert comes up, I can se the HTML object as well, but it says, it has no ID! Any idea?
Maybe I will pass it as parameter...
Gergo
<html>
<head></head>
<body>
<table>
<tr id="row_id_1">
<td width="50"><input type="checkbox" id="chkbx_id_1" value="1"></td>
<td width="50">Simple cell</td>
</tr>
</table>
<script>
function rowHandler(e) {
if (!e) var e = window.event;
if (e.target) targ = e.target.id;
if (e.srcElement) targ = e.srcElement.id;
alert('From TR ' + e.type + ' ' + targ);
}
function cellHandler(e) {
if (!e) var e = window.event;
e.cancelBubble = true;
if (e.stopPropagation) e.stopPropagation();
if (e.target) targ = e.target.id;
if (e.srcElement) targ = e.srcElement.id;
alert('From TD ' +e.type + ' ' + targ);
}
var oRow_1= document.getElementById('row_id_1');
oRow_1.onclick = rowHandler;
if (oRow_1.captureEvents) oRow_1.captureEvents(Event.CLICK);
var cBox_1= document.getElementById('chkbx_id_1');
cBox_1.onclick = cellHandler;
if (cBox_1.captureEvents) cBox_1.captureEvents(Event.CLICK);
</script>
</body>
</html>