jquery - How to read dynamically generated HTML table row's td value? -
in application need enter input values in input controls (textboxes).
then, insert these values in table row, here checking redundant empno values. delete button generated dynamically along id while inserting row of table.
now need delete row when delete button clicked
how select row of selected delete button ? , remove table ?
$("#btninsert").click(function () { var eno = $("#txtempno").val(); var ename = $("#txtempname").val(); var sal = $("#txtsalary").val(); var deptno = $("#txtdeptno").val(); var rowcnt = $("#tblbody tr").size(); if (eno == "" && ename == "" && sal == "" && deptno == "") { alert("enter values"); } else { if (rowcnt == 0) { $("<tr><td id='items" + rowcnt + "'>" + eno + "</td><td>" + ename + "</td><td>" + sal + "</td><td>" + deptno +" <input type='button' value='delete' id='btndelete"+rowcnt+"'/></td></tr>").appendto("#tblbody"); $("input[id^=txt]").val(""); $("input[id^=btndelete]").bind("click", function () { alert("delete button clicked"); }); } else { var dupcount = 0; (var = 0; < rowcnt; i++) { var num = $("#items" + i).html().tostring(); if (eno == num) { dupcount++; } } if (dupcount == 0) { $("<tr><td id='items" + rowcnt + "'>" + eno + "</td><td>" + ename + "</td><td>" + sal + "</td><td>" + deptno + " <input type='button' value='delete' id='btndelete" + rowcnt + "'/></td></tr>").appendto("#tblbody"); $("input[id^=txt]").val(""); $("input[id^=btndelete]").bind("click", function () { alert("delete button clicked"); }); } else { alert("your entered empno exists in table !"); } } } })
here's updated fiddle.
here important line:
js
$(this).parent().parent().remove();
i used click event trigger .remove().
Comments
Post a Comment