• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Add Rows dynamically to a table

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 1061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
If you have a bad day in October, have a slice of banana cream pie. And this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic