jquery append row onclick

Posted by BigDogsBarking on Stack Overflow See other posts from Stack Overflow or by BigDogsBarking
Published on 2010-04-24T17:58:37Z Indexed on 2010/04/24 18:03 UTC
Read the original article Hit count: 208

Filed under:
|
|

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>

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about append