Generate rows using javascript

#1
[eluser]canicasio[/eluser]
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);
cellLeft.appendChild(textNode);

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

el.onkeypress = keyPressTest;
cellRight.appendChild(el);

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

sel.name = 'selRow' + iteration;


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

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

<?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:

http://www.mredkj.com/tutorials/tableaddrow.html

#2
[eluser]pickupman[/eluser]
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.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.