Hmm this forum really doesn't give you long enough to type in your question before logging you out.. well here goes my second attempt:
I'm trying to teach myself javascript with dom scripting and am attempting to write an application as I learn. It's been going fine but I've ran into a problem which is driving me crazy.
I'll start off by explaining what I'm trying to achieve... I'm simply trying to insert an input button into a table at a specific place which calls a function when clicked. For examples sake I'm trying to place it into row 3, column 4 of the table.
So I started off by creating an button that called the javascript to insert that button. This works fine. In the script I first define the new element like so :
[CODE=javascript]var newDelete = document.create Element('input' );
newDelete.setAt tribute('type', 'button');
newDelete.setAt tribute('value' , 'delete');
newDelete.setAt tribute('onclic k', 'test();');[/CODE]
I then insert it into the correct place in the table :
[CODE=javascript]document.getEle mentsByTagName( 'table')[0].firstChild.chi ldNodes[2].childNodes[3].appendChild(ne wDelete);[/CODE]
I realise there are probably better ways to find the correct 'td' in the table but I'm a newbie.
At first it appears to run fine... I click the static button, and the new button appears in the table at the correct position. You can even click the button!!! However, clicking the button does not call the test() function as expected. Looking at the generated html the button looks ok :
[CODE=html]<INPUT onclick=test(); type=button value=delete>[/CODE]
To test whether it was a problem with the html generated I copied the button html into a separate html page and opened it. The button appeared... clicking it called the test() function!
So even though these two buttons are effectively the same... clicking the dynamically generated button does not call the test() function... while clicking the static one does...
Any help would be greatly appreciated!
Ben.
I'm trying to teach myself javascript with dom scripting and am attempting to write an application as I learn. It's been going fine but I've ran into a problem which is driving me crazy.
I'll start off by explaining what I'm trying to achieve... I'm simply trying to insert an input button into a table at a specific place which calls a function when clicked. For examples sake I'm trying to place it into row 3, column 4 of the table.
So I started off by creating an button that called the javascript to insert that button. This works fine. In the script I first define the new element like so :
[CODE=javascript]var newDelete = document.create Element('input' );
newDelete.setAt tribute('type', 'button');
newDelete.setAt tribute('value' , 'delete');
newDelete.setAt tribute('onclic k', 'test();');[/CODE]
I then insert it into the correct place in the table :
[CODE=javascript]document.getEle mentsByTagName( 'table')[0].firstChild.chi ldNodes[2].childNodes[3].appendChild(ne wDelete);[/CODE]
I realise there are probably better ways to find the correct 'td' in the table but I'm a newbie.
At first it appears to run fine... I click the static button, and the new button appears in the table at the correct position. You can even click the button!!! However, clicking the button does not call the test() function as expected. Looking at the generated html the button looks ok :
[CODE=html]<INPUT onclick=test(); type=button value=delete>[/CODE]
To test whether it was a problem with the html generated I copied the button html into a separate html page and opened it. The button appeared... clicking it called the test() function!
So even though these two buttons are effectively the same... clicking the dynamically generated button does not call the test() function... while clicking the static one does...
Any help would be greatly appreciated!
Ben.
Comment