frontline
09-25-2003, 02:24 PM
Hello
im trying to attach dynamic id attribute but for some reason im getting only the last
id name , if you will run this script you will get on the onclick event alert only the "r3" name
no Metter what row you will click. what i was expecting is to get different id name for every
row ("r0","r1","r2","r3").
----------------------------------------------------------------------------------------------------------------------------------------------------------
<HTML>
<HEAD>
<script>
function userSelect(o){alert(o.id)}
function setTable(){
var oRow,oCellText;
var arrNames = "blah1|blah2|blah3|blah4|";
arrNames = arrNames.split("|");
for(var i=0;i<arrNames.length-1;i++){
oRow = TableFirst.insertRow();
oRow.id = "r"+i;
oRow.attachEvent("onclick",function(){userSelect(oRow)});
oCellText = oRow.insertCell();
oCellText.innerHTML = arrNames[i];
}
}
</script>
</HEAD>
<BODY>
<input type="button" onclick="setTable();" value="build"><br>
<table id="TableFirst" border="1" cellspacing="0" cellpadding="0" width="100%" class="font"></table>
</BODY>
</HTML>
-----------------------------------------------------------------------------------
thanks
im trying to attach dynamic id attribute but for some reason im getting only the last
id name , if you will run this script you will get on the onclick event alert only the "r3" name
no Metter what row you will click. what i was expecting is to get different id name for every
row ("r0","r1","r2","r3").
----------------------------------------------------------------------------------------------------------------------------------------------------------
<HTML>
<HEAD>
<script>
function userSelect(o){alert(o.id)}
function setTable(){
var oRow,oCellText;
var arrNames = "blah1|blah2|blah3|blah4|";
arrNames = arrNames.split("|");
for(var i=0;i<arrNames.length-1;i++){
oRow = TableFirst.insertRow();
oRow.id = "r"+i;
oRow.attachEvent("onclick",function(){userSelect(oRow)});
oCellText = oRow.insertCell();
oCellText.innerHTML = arrNames[i];
}
}
</script>
</HEAD>
<BODY>
<input type="button" onclick="setTable();" value="build"><br>
<table id="TableFirst" border="1" cellspacing="0" cellpadding="0" width="100%" class="font"></table>
</BODY>
</HTML>
-----------------------------------------------------------------------------------
thanks