html5 - why can't i delete a row in table from javascript? -


i'm trying build table out javascript, far good. main idea last column checkbox, , when checked row delete. before delete it, need know written in row, i'm checking id. reason doesn't work. can me? thanks

this 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 array     ( i=0; i< users.length ; i++) {      tr = document.createelement('tr');      tr.id = name+" row";       //alert("this 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 + " 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 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 delete function:

function cleanalert(event) {   var checkbox = event.target;   var rowindex;    rowindex = document.getelementbyid(checkbox.name + " row").rowindex;   document.getelementbyid("tbalerts").deleterow(rowindex); } 

i'm not sure how build function gets called, gave every checkbox unique name instead of name-parameter of build()function. see jsfiddle.

notice following line inside for-loop:

var localname = name + i; 

i replaced every occurence of name-variable localname-variable.

i've changed eventlistener listen "click" instead of "checkboxstatechange".


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -