CodeIgniter Forums
Generate rows using javascript - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived General Discussion (
+--- Thread: Generate rows using javascript (/thread-31462.html)

Generate rows using javascript - El Forum - 06-20-2010

Hello, im new using CI and i have a problem:

I have a view and in it, i generate rows for a table using javascript. In that table i have a "select" that present information from a D.B, but it does not prensent all the information form de D.B. only the last record. Here is the code:

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);

// right cell
var cellRight = row.insertCell(1);
var el = document.createElement('input');
el.type = 'text'; = 'txtRow' + iteration; = 'txtRow' + iteration;
el.size = 40;

el.onkeypress = keyPressTest;

// select cell
var cellRightSel = row.insertCell(2);
var sel = document.createElement('select'); = 'selRow' + iteration;

<?php foreach($seleccion as $item):?>

sel.options[0] = new Option('<?php echo $item->DESCRIPCION;?>');

<?php endforeach;?>


$seleccion is an array that has the information from the B.D

for more information please see in the following link what i want to do:

Generate rows using javascript - El Forum - 06-20-2010

Not sure if you are into jQuery, but this would be trivial do with it. jQuery has a function called clone() that will clone/copy any element. I've used it data entry table, that it will automatically add a new row when someone has filled the last available line.