I tried to add rows dynamically to a table. I have cloned the last added row. On every new row the name of the input field should rename with a number +1. For this, I wanted to rename the input fields, but I failed to do it in this way.
Original row
<input type="text" name="myfiels[0]" value="mytext">
First clone row
<input type="text" name="myfiels[1]" value="mytext">
Second clone row
<input type="text" name="myfiels[]" value="mytext">
...
$trNew.find('[name]').each(function () {
var num = this.name.replace(/\D/g, '');
if (!num) {num = 0;}
// Remove numbers by first regexp
// increment number
//this.name = this.name.replace(/\d/g, '') + (1 + parseInt(num, 10));
this.name.replace(/[.+]/,"["+(1 + parseInt(num, 10))+"]");
});
I think the regex is wrong.