1

This post is an extension of Customizing JQuery Cloned row attributes.

What I need to do is copy the row, but be selective as to what new Name and ID to assign to each element. For example, if the element is a Radio button, I do not want to change the name (for grouping purposes).

Also, in the example provided in the fiddle, the 'select' list never gets its name or id updated.

Here is the fiddle: http://jsfiddle.net/radi8/EwQUW/15/

Being new to JQuery, I really appreciate any guidance and help in getting this to work. I hate asking silly questions, but this is the BEST board I have found so far and have always received clear, direct answers.

Community
  • 1
  • 1
radi8
  • 528
  • 3
  • 12
  • 29

1 Answers1

0

Try this

// do Add button options
$("#Add").click(function() {
    var i = ($('#secondaryEmails >tbody >tr').length)+1;
    $("#secondaryEmails >tbody tr:first").clone().find("input,select").each(function() {
        //if(this).(':radio').
        $(this).attr({
            'id': function(_, id) {
                return id + i;
            },
            'name': function(_, name) {
                if($(this).attr("type") == "radio")
                    return name;
                return name + i;
            },
            'value': ''
        });
    }).end().appendTo("#secondaryEmails >tbody").show();
});
// do update button options
$("#update").click(function() {
    // find and display selected row data
    alert('in Update');
    var rowCount = $('#secondaryEmails >tbody >tr').length;

});
// do row double click options
// do row selected by either focusing on email or ship type elements
ShankarSangoli
  • 69,612
  • 13
  • 93
  • 124
  • I was missing this: $("#secondaryEmails >tbody tr:first").clone().find("input,select").each(function() { and this: if($(this).attr("type") == "radio"). Once I got that, the rest will just fall into place!!! Thanks again for the excellent help and support. This project is going to work well. – radi8 Jul 27 '11 at 15:04