dc*******@profe ssionalaccess.c om (Dipin) wrote in message news:<be******* *************** ****@posting.go ogle.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.createEleme nt("TD");
newbutton = doc.createEleme nt("input");
newbutton.name = "newChange"+__u id;
newbutton.width = 15;
newbutton.heigh t = 15;
newbutton.type = "button";
newbutton.oncli ck = "alert('hi' );";
newcol.appendCh ild(newbutton);
alert(newcol.in nerHTML);
newrow.appendCh ild(newcol);
tbl.appendChild (newrow);
__uid++;
window.close();
Any help will be greatly appreciated.
Thanks
Dipin
Aren't you assigning a string to newbutton.oncli ck? I presume that
typeof(newbutto n.onclick) is string:
<input type="button" id='btn1' value='string' /><br>
<input type="button"id ='btn2' value='anonymou s script block'
onclick='return clickHandler(); '/><br>
<input type="button" id='btn3' value='showFunc tion(btn1)'
onclick="showFu nction(document .getElementById ('btn1'));" /><br>
<input type="button" id='btn4' value='showFunc tion(btn2)'
onclick="showFu nction(document .getElementById ('btn2'));" />
<script type='text/javascript'>
function clickHandler(){
alert('in clickhandler');
return 1;
}
function showFunction(bt n){
alert(btn.oncli ck.toString() + '\ntype: ' + typeof(btn.oncl ick));
}
document.getEle mentById('btn1' ).onclick = 'return clickHandler(); ';
</script>