Skip to content

Instantly share code, notes, and snippets.

@wyanez
Created August 7, 2013 02:35
Show Gist options
  • Save wyanez/6170718 to your computer and use it in GitHub Desktop.
Save wyanez/6170718 to your computer and use it in GitHub Desktop.
Función que renombra cada uno de los elementos dentro de un grupo de fieldsets anidados (un fieldset por registro) reenumerando el indice en el name (Ej: name=> txtname[1] lo cambia a txtname[0] si corresponde al primer elemento)
function recount(){
c = 0;
fieldset = $('form > fieldset ');
$.each( fieldset.children('fieldset'), function(){
$.each( $(this).children('[name]'), function(){
name = $(this).attr('name');
newname = name.replace(/\[\d+\]/g, '['+$c+']');
$(this).attr('name',newname);
console.log('name '+name+' -> '+newname);
});
c++;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment