[thelist] adding an event to a DOM dynamically added row

Peter-Paul Koch gassinaumasis at hotmail.com
Sat Mar 15 05:27:18 CST 2003


>I am adding rows to a table with the DOM. They now want to add an
>onclick event as well. They were trying setAttribute() with no
>success. Anyone know how we could accomplish this? Here is a snippet
>of how we are doing it:
>
>var rowNum = 3;
>function addPerfRow(bodyName, tableName)
>{
>	docBody = document.getElementById(bodyName);
>	tableName = document.getElementById(tableName);
>	newRow = document.createElement("TR");
>	newRow.className = "GridItem";
>	for (i = 0; i < 7; i++)
>	{
>		cell = document.createElement("TD");
>		field = document.createElement("INPUT");
>		switch(i)  // have like 7 cells
>		{
>                          // we want an onclick on this button for
>example

field.onclick = functionName;

Don't use setAttribute and getAttribute, except when there is no other way 
to do what you want to do.

--------------------------------------------------
ppk, freelance web developer
Interaction, copywriting, JavaScript, integration
http://www.xs4all.nl/~ppk/
Column "Keep it Simple": http://www.digital-web.com/columns/keepitsimple/
W3C DOM Compatibility Table, expanded & updated
http://www.xs4all.nl/~ppk/js/index.html?version5.html
--------------------------------------------------


_________________________________________________________________
Help STOP SPAM with the new MSN 8 and get 2 months FREE*  
http://join.msn.com/?page=features/junkmail



More information about the thelist mailing list