I have a set of inputs which can be duplicated, but I then need to increment the array value of them. How do I do this?
<input type="text" name="person[0][name]">
<input type="text" name="person[0][age]">
This can then be duplicated, but I need to change the new inputs to be like:
<input type="text" name="person[1][name]">
<input type="text" name="person[1][age]">
I have got so far:
cloned.find('input, select').each(function(){
var $this = $(this);
$this.attr('name',
$this.attr('name').match(/\[\d+]/g, '[' + what_goes_here + ']')
);
});
Where cloned
is my last group of inputs.
What do I do with the value of what_goes_here
?