Change names of appended table row fields jQuery
I have a table in an html form containing a table that a row is added to
every time a button is clicked. When each row is added, I want the name
and id of each field in the new row (there are four) to be updated from
"Id.0" in the first row to "Id.1" in the second row and then "Id.2" in the
third, etc. I can accomplish this with the id no problem using
var next=$("#QualificationRequirements tr:last").clone();
fixIds(next,nexdex);
nexdex++;
$("#QualificationRequirements").append(next);
function fixIds(element, counter) {
$(element).find("[id]").add(element).each(function() {
this.id = this.id.replace(/\d+$/, "")+counter;
});
}
However I have found that the same logic does not apply to the name
attribute, and
$(element).find("[name]").add(element).each(function() {
this.name = this.name.replace(/\d+$/, "")+counter;
});
causes an error.
Can anyone see what I'm doing wrong? Thanks!
No comments:
Post a Comment