Forum Moderators: open

Message Too Old, No Replies

calling javascript in a dynamically generated html element using JS

setting JS in a dynamically generated element

         

kevinjohn

12:03 pm on Jul 4, 2005 (gmt 0)

10+ Year Member



Hi,
I was able to generate the html elements dynamically in javascript using "createElement' and 'appendChild' and i could see the dynamicaly generated elements in the web page( let us say a text box).

Now my query is:

How to call a javascript function from the dynamically generated html element.

for example:
1) i have generated a text box using a javascript function.
2) Now i have to call another function when that text box is clicked.How to add a JS function here?

Can any one please let me know?

kevinjohn

4:53 am on Jul 5, 2005 (gmt 0)

10+ Year Member



Can any one please help me out in this regard?
Thanks

Dijkgraaf

5:13 am on Jul 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here is an example I came accross on a site called quirksmode.
[quirksmode.org ]

if (document.getElementById && document.createElement)
{
var butt = document.createElement('BUTTON');
var buttext = document.createTextNode('Ready!');
butt.appendChild(buttext);
butt.onclick = saveEdit;
}

Hope that helps you.