jsp and javascript
i want a table and i want to add rows to that table. I can do it but what i don't know is that instead of adding input text i want to add select list (drop down list) and i want to populate that drop down list with data from a database. So far my javascript for adding rows with input fields is just like this:
function addRowToTable(){
var tbl = document.getElementById('tableVisitantes');
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);
// nro cell
var nroCell = row.insertCell(0);
var textNode = document.createTextNode(iteration);
nroCell.appendChild(textNode);
// nombre cell
var nombreCell = row.insertCell(1);
var sel = document.createElement('input');
sel.type ='text';
sel.name ='txtRow' + iteration +'1';
sel.id ='txtRow' + iteration +'1';
sel.size = 20;
nombreCell.appendChild(sel);
// tipo doc cell
var tipoDocCell = row.insertCell(2);
var sel1 = document.createElement('select');
//sel1.type = 'text';
//sel1.name = 'txtRow' + iteration + '2' ;
//sel1.id = 'txtRow' + iteration + '2';
//sel1.size = 20;
tipoDocCell.appendChild(sel1);
// nro doc cell
var nroDocCell = row.insertCell(3);
var sel2 = document.createElement('input');
sel2.type ='text';
sel2.name ='txtRow' + iteration +'3';
sel2.id ='txtRow' + iteration +'3';
sel2.size = 20;
nroDocCell.appendChild(sel2);
}
function removeRowFromTable(){
var tbl = document.getElementById('tableVisitantes');
var lastRow = tbl.rows.length;
if (lastRow > 2) tbl.deleteRow(lastRow - 1);
}

