I have a table that populates with contents from a database. A user should be able to add as many new entries as they want to the table (let's ignore the 'save' button for now).
I attempt to add new rows to the table with
$("#businesscategorytable tfoot").append(addNewRow);
where addNewRow is formatted like the other rows in the table. However, this procedure does not work. What is even more confusing is that a similar module was used in a separate page of the project I'm working on and everything functions properly.
Here's a Stack Snippet that provides a bare-bones mock-up of what I'm working with:
$(function() {
//Remove Row Function for Business Category Tables
$("table[id='businesscategorytable']").on("click", "input[id='btnDeleteRow']", function() {
$(this).closest('tr').hide(); //hiding rows instead of removing so we only commit on 'Save'
});
//End Remove Row Function for Tables
//Add Row Function for Business Category Tables
$("input[id='btnAddBusinessRow']").click(function() {
var addNewRow = "<tr><td style=\"display: none\"><input type=\"hidden\" class=\"hdnBusinessCatId\" id=\"hdnBusinessCatId" + idCount + "\" />" +
"<td><input type=\"text\" id=\"businessCat" + idCount + "\" size=\"12\"></td>" +
"<td><input type=\"text\" id=\"businessColor" + idCount + "\" size=\"8\" value=\"$\"></td>" +
"<td><input type=\"button\" id=\"btnDeleteRow\" value=\"Delete\"\"></td>" +
"</tr>";
$("#businesscategorytable tfoot").append(addNewRow);
idCount++;
});
//End Add Row Function
});
<table border="1" id="businesscategorytable">
<thead>
<tr style="color:white;background-color:darkgray">
<th>Category Name</th>
<th>Color on Map</th>
</tr>
</thead>
<tbody>
<tr>
<td style="display: none">
<input type="hidden" class="hdnBusinessCatId" id="0" />
</td>
<td>
<input type="text" id="txtCategoryName0" size="12" value="0">
</td>
<td>
<input type="text" id="txtCategoryId0" size="8" value="Red">
</td>
<td>
<input type="button" id="btnDeleteRow" value="Delete">
</td>
</tr>
</tbody>
<tfoot>
<tr>
<td style="display: none">
<input type="hidden" class="hdnBusinessCatId" id="hdnBusinessCatId0" />
</td>
<td>
<input type="text" id="businessCat0" size="12" />
</td>
<td>
<input type="text" id="businessColor0" value="$" size="8" />
</td>
<td>
<input type="button" id="btnDeleteRow" value="Delete" />
</td>
</tr>
</tfoot>
</table>
<input type="button" id="btnAddBusinessRow" value="Add" />
Any ideas as to why this may not be working?