Click to See Complete Forum and Search --> : dynamically generated buttons problem


tkweb
12-17-2002, 04:03 AM
Hi,
my code creates buttons which should launch different functions.

function addTable(){
var mCloneNode = myTable.cloneNode(true);
document.body.insertBefore(mCloneNode);
var addinput = mCloneNode.getElementsByTagName("INPUT")[12];
var onclick = "test()";
addinput.setAttribute("ONCLICK", onclick);
addinput.setAttribute("value", "works!");
}

For some reason I'm not able to set "onclick"-attribute (INPUT[12] is a button) while setting "value"-attribute works fine. It holds the "onclick"-attribute from the myTable (original table).

Any ideas?

thanks!

gil davis
12-17-2002, 06:39 AM
Are you sure that "ONCLICK" is an attribute? I believe that it is an event, which is different from an attribute.

I am fairly certain that this syntax will work:

addinput.onclick = test;

I also read this in the DOM Level 2 Events:

addinput.addEventListener("click", test, false);