Created
August 7, 2013 02:35
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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