I have this code that changes input fields name attribute value, works great in all major browsers except IE8, IE7 and IE6. For IE the name just stay name="participant_name[{i}]", should be name="participant_name[1]".
var i = 1;
var input_name = null;
$('.dubl input').each(function () {
var new_input_name = $(this).attr('name').substring(0, $(this).attr('name').indexOf('['));
if (input_name !== new_input_name) {
input_name = new_input_name;
i = 1;
}
$(this).attr('name', input_name + '[' + i + ']');
i++;
});
HTML
<input type="text" name="participant_name[{i}]">
It is in fact changing the attribute
namecorrectly in IE as well. However, I think the problem you may be experiencing is that when you submit the form, it isn’t the updated fieldname.IE doesn’t take into account that
namechange and as such, when the form is sent, it is still using the samenameas it was when it was created. To fix this, you can either re-add it to the DOM the form/element when you change the name attribute.http://jsfiddle.net/niklasvh/wbnhS/ you can test it there, the attribute does change or if you inspect the DOM in IE.