goodieboy wrote:
What am I doing wrong? Here is an example:

for(i=0; i<10; i++){
  $('input').each(function(){
    $(this).attr('name', i);
  });
}

John's response shows how to get this, if that index is really what you want. Why this goes wrong, though is a different matter. You have a nested loop. The .each loop is setting the name attribute to the current value of i for each input. The the outer loop runs again and resets each one to a new value.

If this is just a simplification of what you're doing though, and you need something more than the index, you might also run into issues with closures. Google should help with that:

    http://www.google.com/search?q=javascript+closure

Good luck,

  -- Scott

Reply via email to