I am trying to create a JS function that creates a new row every time a new record is added to the database (from another program that checks periodically). Right now, I can get a function to check db, add a record to the table and display it dynamically. The first column is the user ID, and the second column is the problems I am facing. I would like to include a drop-down list, but I'm not sure how to add options to it. I have a dropdown in the second column, but no options. Anyone have any suggestions?
function addRow(tableID, user) {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var colCount = table.rows[0].cells.length;
for(var i=0; i<colCount; i++) {
var opt = document.createElement("option");
tabbody=document.getElementsByTagName("tbody").item(2);
cell1 = document.createElement("TD");
cell2 = document.createElement("TD");
textnode1=document.createTextNode(user);
textnode2=document.createElement("select");
textnode2.setAttribute('id', 'focus');
textnode2.options.add(opt);
cell1.appendChild(textnode1);
cell2.appendChild(textnode2);
row.appendChild(cell1);
row.appendChild(cell2);
tabbody.appendChild(row);
var newcell = row.insertCell(i);
newcell.innerHTML = table.rows[0].cells[i].innerHTML;
Here is the HTML that it sends:
<th colspan="2">Pending Alerts</th>
<tr>
<th>User</th>
<th>Action</th>
</tr>
<tbody>
</tbody>
source
share