Probably not the most efficient function, but should work:

$('#ThemesList li').each(function(index){
  $('input:hidden', this).each(function(){
       var fixName = $(this).attr('name').replace(/\[\d\]/, '['+index
+']');
       $(this).attr('name', fixName);
  });
});


- ricardo

On Feb 11, 7:19 pm, shapper <mdmo...@gmail.com> wrote:
> Hello,
>
> I am adding and removing a items from a list, using JQuery, which is
> rendered has follows:
>
> <ol id="ThemesList">
>   <li">
>     <input type="hidden" name="Themes[0].Subject" value="A" />
>     <input type="hidden" name="Themes[0].Levels" value="L1,L2" />
>     <input type="hidden" name="Themes[0].Description" value="Paper" />
>   </li>
>   <li">
>     <input type="hidden" name="Themes[2].Subject" value="B" />
>     <input type="hidden" name="Themes[2].Levels" value="L1,L5" />
>   </li>
>   <li">
>     <input type="hidden" name="Themes[5].Subject" value="D" />
>     <input type="hidden" name="Themes[5].Levels" value="L2,L4" />
>     <input type="hidden" name="Themes[5].Description" value="Book" />
>   </li>
> </ol>
>
> Every time I add or remove a Theme I need to be sure that the list is
> ordered (name) starting with Themes[0].
>
> So basically I need to loop through each list item in list ThemesList.
> - In first list item all HIDDEN inputs names should start with "Themes
> [0]"
> - In second list item all HIDDEN inputs names should start with "Themes
> [1]"
> ...
>
> So in this example, "Themes[2]. ..." would become "Themes[1]. ..." and
> "Themes[5]. ..." would become "Themes[2]. ..."
>
> Could someone please help me out?
>
> I have no idea how to do this.
>
> Thanks,
> Miguel

Reply via email to