How can I attach a listener to multiple radio buttons?
<p>I have three radio buttons like this:</p>

<pre><code>&lt;input type="radio" name="P_1" value="1"&gt;Yes&lt;/input&gt;
&lt;input type="radio" name="P_1" value="2"&gt;No&lt;/input&gt;

&lt;input type="radio" name="P_2" value="1"&gt;Yes&lt;/input&gt;
&lt;input type="radio" name="P_2" value="2"&gt;No&lt;/input&gt;

&lt;input type="radio" name="P_3" value="1"&gt;Yes&lt;/input&gt;
&lt;input type="radio" name="P_3" value="2"&gt;No&lt;/input&gt;
</code></pre>

<p>I am trying to add a listener to each of these radio buttons so that I will be notified when they change. I am doing something like this:</p>

<pre><code>for (var i = 1; i &lt;= 3; i++) {
            $("input[name='P_" + i + "']").live('change', function () {
                doProcessing("P_" + i, $("input[name='P_" + i + "']:checked").val());
            });
}
</code></pre>

<p>However, this does not seem to work. It calls <code>doProcessing</code> with <code>i</code> set to 4 because that is the value of <code>i</code> at the end of the for loop. What is the correct way of adding an event handler in my case?</p>
