The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript JS Add/Remove Row in Table Reply To: JS Add/Remove Row in Table


So, I’m still kind of a noob on JS, but you may want to use jQuery here.

First things first: you really shouldn’t use tables for anything other than tabular data, I would try using divs and whatnot. But, since you may have your own reasons, let’s start.

You’ll need is get the code for that row in a string, and the data you want to change in variables. Something like:

var formIndex = 1;
var newRow = '<tr><td>Some content<tr><td>'
newRow += '<td><textarea id="'+formIndex+'"></textarea>';

Then, you can use jQuery’s append $('.emptyDiv').append(newRow) to include that new code, not forgetting to increase that index formIndex+= 1