dc*******@professionalaccess.com (Dipin) wrote in message news:<be**************************@posting.google. com>...
Hi All;
I have this javascript which is adding a new button to the column in
the row which is created dynamically, the innerhtml shows that the
onclick event is correctly added but it never gets invoked when I
click it.
newcol = doc.createElement("TD");
newbutton = doc.createElement("input");
newbutton.name = "newChange"+__uid;
newbutton.width = 15;
newbutton.height = 15;
newbutton.type = "button";
newbutton.onclick = "alert('hi');";
newcol.appendChild(newbutton);
alert(newcol.innerHTML);
newrow.appendChild(newcol);
tbl.appendChild(newrow);
__uid++;
window.close();
Any help will be greatly appreciated.
Thanks
Dipin
Aren't you assigning a string to newbutton.onclick? I presume that
typeof(newbutton.onclick) is string:
<input type="button" id='btn1' value='string' /><br>
<input type="button"id='btn2' value='anonymous script block'
onclick='return clickHandler();'/><br>
<input type="button" id='btn3' value='showFunction(btn1)'
onclick="showFunction(document.getElementById('btn 1'));" /><br>
<input type="button" id='btn4' value='showFunction(btn2)'
onclick="showFunction(document.getElementById('btn 2'));" />
<script type='text/javascript'>
function clickHandler(){
alert('in clickhandler');
return 1;
}
function showFunction(btn){
alert(btn.onclick.toString() + '\ntype: ' + typeof(btn.onclick));
}
document.getElementById('btn1').onclick = 'return clickHandler();';
</script>