Faqts : Business : Programming : Shopping For You : JavaScript : Event handling

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

17 of 27 people (63%) answered Yes
Recently 6 of 10 people (60%) answered Yes

Entry

If you do document.write("<input type=button>"); how can you then add an onClick handler dynamically? doc.forms[0].elements[0].onclick=f()doesn't work

Aug 24th, 2001 09:14
Lobo López, stoyan shopov,


You can add any handler dynamically.
There's no relationship between the form you define the element and the 
form you add a handler dynamically.
The right way for your sentence is:
document.forms[0].elements[0].onclick=f;