faqts : Computers : Programming : Languages : JavaScript : Tables

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

3 of 10 people (30%) answered Yes
Recently 3 of 10 people (30%) answered Yes

Entry

How can I add events to dynamically created rows?

Nov 4th, 2003 08:42
Sudharsan Srini, Paul Deason,


Hi,
You will be able to create events for a dynamically added table row as 
specified below.
Dont try to see the "View source" in the browser. It may not show you 
the newly created Rows and its events properly. Instead try wrapping 
the table with a 
<FIELDSET id="fs1"> .
Add a TEXTAREA to the code where you can view the contents and events 
of the newly added TR.
------------------------------------------------
Sample code 
------------------------------------------------
var tr = document.all[tableID].insertRow();
tr.onClick = "fnTRClicked()";
// adding the inner text of the FIELDSET to the textarea just to show 
you that the new row/cell with the specified Event is added. 
// If you copy this code and put in a new HTML file and click on the 
table row the onClick event will be fired. 
textarea1.value = document.all['fs2'].innerHTML
// tableID is the ID of the table where i am adding rows dynamically. 
-- Hope this helps.