*EDIT --- Trying an even more simplified version.... Still doesn't work... Returns $(this).closest is not a function error... *
$("#fitable input[name^=f1]").focus(function() {
var newRow = '<tr><td></td><td></td><td></td><td></td></tr>';
$(this).closest("tbody").append(newRow);
});
Original Post
Pretty new to jQuery, so I'm hoping someone can help me out... There's a couple of things going on here... Help with any part of it is appreciated.
For starters, I'm trying to append a row to a table when a user clicks in the first enabled input field for that row. Here's the code I'm trying to use:
$("#fitable > tbody > tr > td > input").bind('focus', function() {
if($(this).attr('disabled', false)) {
$(this).click(function() {
var newRow = '<tr><td><input name="f1[]" value="" /><label>CustNew</label></td><td><input name="field_n1[]" value="" /><label>N1</label></td><td><input name="field_n2[]" value="" /><label>N2</label></td></tr>';
$(this).closest("tbody").append(newRow);
});
}
});
If it's helpful, here's the html:
<table id="fitable">
<tbody>
<tr valign="top">
<td><input disabled="disabled" name="cust" id="edit-cust" value="[email protected]" type="text"><label>Cust</label></td>
<td><input name="field_n1[]" value="" type="text"><label>N1</label></td>
<td><input name="field_n2[]" value="" type="text"><label>N2</label></td>
</tr>
</tbody>
</table>