Sunday, 11 August 2013

Change Select Name after Row Clone

Change Select Name after Row Clone

I have a table row that a user can clone if they need additional rows, and
the select name is increased via jQuery at the same time as the clone.
However continually cloning the row doesnt increase the row count as it
should.
Some help on this one would be really appreciated. Code Below.
function addRow() {
$("#addRow").live('click', function() {
var tr, clone, fields;
tr = $(this).closest('.tr_clone');
clone = tr.clone();
tr.after(clone);
tr.find('.addButton').empty();
$("tr:last").css({backgroundColor: 'yellow', fontWeight: 'bolder'});
fields = $("tr:last").find("select[name^='row-']");
fields.attr('name', 'row-' + (fields.length + 1));
name = fields.attr("name");
alert(name);
});
}

No comments:

Post a Comment