I'm trying to build a table out from JavaScript, so far so good. The main idea is that the last column will be a checkbox, and when it will be checked the row will delete. before i delete it, i need to know what was written in this row, so i'm checking the id. for some reason it doesn't work. can someone help me? Thanks
this is the building function
function build(name){
var myTableDiv = document.getElementById("alertsDiv");
var table = document.createElement('TABLE');
var tr;
var i, j;
table.style="width:90%; text-align: center; font-size: 13px; border: 1px solid black; border-collapse: collapse";
table.id = "tbAlerts";
var tableBody = document.createElement('TBODY');
table.appendChild(tableBody);
tableBody.id = "tbBody";
//users is an array
for ( i=0; i< Users.length ; i++){
tr = document.createElement('TR');
tr.id = name+" row";
//alert("this is the tr id: " +tr.id);
tableBody.appendChild(tr);
//the time
td = document.createElement('TD');
var d = new Date();
td.appendChild(document.createTextNode( d.getHours() +":"+ d.getMinutes() +":"+ d.getSeconds() ));
tr.appendChild(td);
//severity
td = document.createElement('TD');
td.appendChild(document.createTextNode("minor"));
tr.appendChild(td);
//alert
var td = document.createElement('TD');
td.appendChild(document.createTextNode(name + " is dead"));
tr.appendChild(td);
//comments
td = document.createElement('TD');
var txtBox = document.createElement('INPUT');
txtBox.type = 'text';
txtBox.placeholder="comments";
td.appendChild(txtBox);
tr.appendChild(td);
//Acknowledge - ***THIS IS THE IMPORTANT THING***
td = document.createElement('TD');
var newCheckBox = document.createElement('INPUT');
newCheckBox.type = 'checkbox';
rowsNum++;
newCheckBox.name=name;
newCheckBox.addEventListener("CheckboxStateChange", cleanAlert, false);
td.width='10px';
td.appendChild(newCheckBox);
tr.appendChild(td);
}
myTableDiv.appendChild(table);
}
}
this is the delete function
function cleanAlert(event){
var checkbox = event.target;
var rowIndex;
rowIndex = document.getElementById(checkbox.name + " row").rowIndex;
document.getElementById("tbAlerts").deleteRow(rowIndex);
}
Aucun commentaire:
Enregistrer un commentaire