Unexpected JS/jQuery Loop Behavior
<p>I have the following loop. The goal is to automatically show text boxes when a user chooses certain options in a dropdown list.</p>

<p>For some reason, in the following code, the loop assigns the "sponsor" field to the associated array for "blurb". I cannot figure out why. How can I make this work?</p>

<p>Thanks so much.</p>

<pre><code>function add_fields_on_change ()
{
    var map = {
        "sponsor"   :   Array("New Sponsor", "new_sponsor"),
        "blurb"     :   Array("New Blurb Suggestion", "new_blurb")
    };
    for (field in map)
    {
        alert($('.bound[name='+field+']').val()); //alerts as expected
        $('.bound[name='+field+']').change(function() {
            alert(map[field][0]); //alerts "New Blurb Suggestion" for both "sponsor" and "blurb" fields
            if ($(this).val() == map[field][0])
            {
                 $('.hidden[name='+map[field][1]+']').show();
            }
        });
    }
}
</code></pre>
