Hi Miguel, another idea: I guess you need the Themes[0].* construct to process the form submit with a PHP script? I'm not 100% sure with this PHP stuff, but can't you pass a list of Themes[].*, Themes[].*, ... without an index between [] to PHP and PHP will automatically create an array out of it?
by(e) Stephan 2009/2/10 mkmanning <michaell...@gmail.com>: > > You can just check the length of the child <li> elements of ul#Themes: > > $('#AddTheme').bind('click', function(){ > // Other code > var len = $('#Themes li').length; > $theme = $('<li class="Themes"></li>').appendTo > ('#Themes'); > $theme.append('<input type="hidden" name="Themes['+len > +'].Subject" > value = "' + $subject.val() + '" />'); > $theme.append('<input type="hidden" name="Themes > ['+len+'].LevelsCsv" value = "' + levelsTypes.join(",") + '" />'); > $theme.append('<input type="hidden" name="Themes > ['+len+'].Description" value = "' + description.val() + '" />'); > }); > > > On Feb 8, 8:13 am, Stephan Veigl <stephan.ve...@gmail.com> wrote: >> Hi Miguel, >> >> you could use a global counter. >> e.g. >> >> var themesCounter = 0; >> $('#AddTheme').bind('click', function(){ >> ... >> $theme.append('<input type="hidden" >> name="Themes[themesCounter].Subject" value = "' + $subject.val() + '" >> />'); >> ... >> themesCounter++; >> }); >> >> by(e) >> Stephan >> >> 2009/2/8 shapper <mdmo...@gmail.com>: >> >> >> >> > Hi, >> >> > I am adding list items to a list as follows: >> >> > $('#AddTheme').bind('click', function(){ >> >> > // Other code >> >> > $theme = $('<li class="Themes"></li>').appendTo >> > ('#Themes'); >> >> > $theme.append('<input type="hidden" name="Themes[0].Subject" >> > value = "' + $subject.val() + '" />'); >> > $theme.append('<input type="hidden" name="Themes >> > [0].LevelsCsv" value = "' + levelsTypes.join(",") + '" />'); >> > $theme.append('<input type="hidden" name="Themes >> > [0].Description" value = "' + description.val() + '" />'); >> >> > }); >> >> > Basically, every time I add a new item I want to give the next number >> > to Themes[0], i.e., Themes[1]. >> >> > If I add 3 themes I will have Themes[0], Themes[1], Themes[2] >> >> > Basically, I need to have at all times themes numbered as 0, 1, 2, ... >> >> > Could someone please help me out? >> >> > Thanks, >> > Miguel >> >> > Just in case, here is my entire code fully commented: >> >> > $('#Cancel').click(function() { location.href = '/Account/ >> > List'; }); >> >> > // Themes >> >> >> > // Define remove event >> > $('.Remove').livequery('click', function(event) { >> > $(this).parent().remove(); >> > }); >> >> > // Bind add button >> > $('#AddTheme').bind('click', function(){ >> >> > // Define valid >> > var valid = new Boolean(true); >> >> > // Define fields >> > $description = $('#Description'); >> > $levels = $('input[name="Levels"]:checked + label'); >> > $levelsTypes = $('input[name="Levels"]:checked'); >> > $subject = $('#Subject option:selected'); >> >> > // Map levels >> > levels = $levels.map(function() { return $(this).text(); }).get >> > (); >> > levelsTypes = $levelsTypes.map(function() { return $(this).val >> > (); }).get(); >> >> > // Check subject >> > if (!$subject.val()) { valid = false; } >> >> > // Check levels >> > if (!levels.length) { valid = false; } >> >> > // Check boolean >> > if (valid) { >> >> > // Define theme >> > $theme = $('<li class="Themes"></li>').appendTo >> > ('#Themes'); >> >> > // Add fields >> > $theme.append($subject.text()).append('<br />'); >> > $theme.append( Levels(levels) + '<br />' ); >> > if ($description.val()) { $theme.append($description.val >> > ()).append('<br />'); } >> >> > // Add button >> > $theme.append('<a href="#Remove" class="Remove">Remover</ >> > a>'); >> >> > // Add inputs >> > $theme.append('<input type="hidden" name="Themes[0].Subject" >> > value = "' + $subject.val() + '" />'); >> > $theme.append('<input type="hidden" name="Themes >> > [0].LevelsCsv" value = "' + levelsTypes.join(",") + '" />'); >> > $theme.append('<input type="hidden" name="Themes >> > [0].Description" value = "' + description.val() + '" />'); >> >> > // Add input >> > //$theme.append(' <input type="hidden" name="Themes" value = >> > "' + theme + '" />'); >> >> > } >> >> > }); >> >> > // Levels >> > function Levels(levels) { >> >> > // Check levels >> > if (levels.length < 2) return levels.join(''); >> >> > // Define first >> > var first = levels.slice(0, -1), last = levels.slice(-1); >> >> > // Define result >> > var result = first.join(', '); >> >> > // Check last >> > if (last) { result += ' and ' + last; } >> >> > // Return results >> > return result; >> >> > } // Levels