Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Add Rows dynamically to a table

 
Nee Kat
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to add rows to a table dynamically .i.e. by using JavaScript. I was able to add row using the follwoing code I found over the net. The problem is I have to create a dropdown in couple of cells in the new added row and add certain predefined values in it using cfquery.
But with this code I was not able add that as this adds a text box. Any changes in this code to add the drop down would be helpful.

function addRowToTable()
{
var tbl = document.getElementById('tblSample');
var lastRow = tbl.rows.length;
// if there's no header row in the table, then iteration = lastRow + 1
var iteration = lastRow;
var row = tbl.insertRow(lastRow);

// left cell
var cellLeft = row.insertCell(0);
var textNode = document.createTextNode(iteration);
cellLeft.appendChild(textNode);

// right cell
var cellRight = row.insertCell(1);
var el = document.createElement('input');
el.setAttribute('type', 'text');
el.setAttribute('name', 'txtRow' + iteration);
el.setAttribute('id', 'txtRow' + iteration);
el.setAttribute('size', '40');
el.onekeypress = keyPressTest;
cellRight.appendChild(el);
}

I am unable to post the HTML as it is not allowed to post certain functions in JS ( I got this in the error)



Thanks!
 
Chris Baron
Ranch Hand
Posts: 1061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Nee Kat:
I am unable to post the HTML as it is not allowed to post certain functions in JS ( I got this in the error)

One isn't allowed to post event-handlers (onclick, onchange etc).
Just replace the "o" by "#&111;" (#&111;nclick, #&111;nchange etc).
cb
[ October 25, 2005: Message edited by: Chris Baron ]
 
Nee Kat
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been able to create a dropdown box but still looking for a way to populate it. Please help me.

Regards,
nee
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the values are from the server you would have to use Ajaxor submit the page to the server. If you are filling the values from JavaScript, you can use JavaScript's new Option(). Search Google.

Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic