The following .js clones a selected table row to another table when the target row's button is pressed. One of the cells in the row has a checkbox with id="vrbl." As you can see from my code below I want to add a textarea to the cloned row that is disabled if the checkbox is not checked. I know I am not identifying and evaluating the checkbox's "checked" status appropriately but I am struggling to get the code to work here. Appreciate any help!
$(document).ready(function() {
var items = [];
$("button").click(function() {
var newTr = $(this).closest("tr").clone();
var newButtonHTML = "<input type='button' value='Delete' style='font-size: 10px;' onclick='deleteRow(this)'/>";
if ($(newTr).children("#vrbl").prop('checked')) {
var newtextarea = "<textarea></textarea>"
}
else {
var newtextarea = "<textarea disabled></textarea>"
};
$(newTr).children("td:nth-child(6)").html("").html(newtextarea);
items.push(newTr);
$(newTr).children("td:nth-child(7)").html("").html(newButtonHTML);
items.push(newTr);
newTr.appendTo($("#myTable2"));
});
})
if (document.getElementById("vrbl"+this.id).checked==true) {
Above worked! Appreciate the tip.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.