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

}

[2672 byte] By [pompeighuIIa] at [2007-11-27 7:27:32]
# 1

javascript doesn't have any options for database access.

Seeing as it is running on the client, you can't directly call Java/JSP code either.

The best approach would probably be some sort of Ajax call. ie when you add a new row, send a request to the server for the list of items that should be in the select dropdown list, and then put that dynamically onto the page.

evnafetsa at 2007-7-12 19:07:49 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
ok, but if i want to populate some static options? how would i do it?
pompeighuIIa at 2007-7-12 19:07:49 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...