Well the syntax in both examples are wrong! :) thanks to my original
example. Fixing the syntax still gives the same results. The value set
in the inner "each" is the last value set to "i".

Try this:

$('div').each(function( i ){
        $(this).find('input').attr('name', 'option_num_' + i);
});

All elements will have the same name. the i appended to the name will
have the last/greatest value of i. I realize that these are real/
realtime loops, their event handlers getting fired at different times,
but I still can't find a solution?! Anymore ideas?

Thanks,
Matt

On Aug 23, 12:03 pm, Scott Sauyet <[EMAIL PROTECTED]> wrote:
> goodieboy wrote:
> > Hi John,
>
> > Actually that was a bad example sorry! What about something like this:
>
> > $('form div.options').each(){function( i ){
> >   $(this).children('[EMAIL PROTECTED]').each(function(){
> >     $(this).attr('name', 'option_num_' + i);
> >   });
> > });
>
> Try this:
>
> $('form div.options').each(){function( i ){
>    var j = i;
>    $(this).children('[EMAIL PROTECTED]').each(function(){
>      $(this).attr('name', 'option_num_' + j);
>    });
>
> });
>
> If that works, then try looking up Javascript closures.  If not, then
> I'm a little stumped.
>
>    -- Scott

Reply via email to