function createDynamicTable(tbody, rows, cols) {
if (tbody == null || tbody.length < 1) return;
for (var r = 1; r <= rows; r++) {
var trow = $("<tr>");
for (var c = 1; c <= cols; c++) {
var input = $("<input />");
$("<td>")
.addClass("tableCell")
.append(input)
.data("col", c)
.appendTo(trow);
}
trow.appendTo(tbody);
}
}
This script is called on the on change event of a select tag, whenever I change the option and generate a table.
I’m not sure I understand your problem correctly but I would certainly try moving
outside the for loops, if it won’t solve anything else, it would make the function more efficient. also I suspect that because of scoping issues:
won’t have trow variable defined when you try to append
edit: I’ve made a working jsBin with this working. I don’t understand what is the exact problem or question:
another edit: If the question is (as I presume) about binding to select box change, I’ve changed the JsBin accordingly .