Jquery loop - capture the value
<p>I am running this loop in php but using a jquery click function during the output.  How can i record which instance of $i was clicked.  When I use $(this) it returns the id.  </p>

<p>The $('#pid-form').val('$frame_id[$i]') actually has the number i want as the value but I am not sure how to use it or convert it to a variable that I can use.</p>

<pre><code>for($i = 0; $i &lt; $numRecords2; $i++){

$prod_id = $_SESSION['prod_array'][$frame_id[$i]];
echo"

$('#frame$frame_id[$i]').click(function() {
 $('#top-left-frame').html('&lt;img src=\"$upper_left[$i]\" alt=\"\" /&gt;');
 $('#top-mid-frame').css('background-image','url($upper_middle[$i])'); 
 $('#top-right-frame').html('&lt;img src=\"$upper_right[$i]\" alt=\"\" /&gt;');
 $('#mid-left-frame').css('background-image','url($middle_left[$i])'); 
 $('#mid-right-frame').css('background-image','url($middle_right[$i])'); 
 $('#bottom-left-frame').html('&lt;img src=\"$bottom_left[$i]\" alt=\"\" /&gt;');
 $('#bottom-mid-frame').css('background-image','url($bottom_middle[$i])'); 
 $('#bottom-right-frame').html('&lt;img src=\"$bottom_right[$i]\" alt=\"\" /&gt;');
 $('#frame-select').html('$prod_id');
 $('#pid-form').val('$frame_id[$i]');
 $('#oa_id-form').val('$prod_id');
 var frameState = $(this).attr('id');
 $.cookie('frameState', frameState, { expires: 7 });  
    alert($.cookie('frameState') + ' was clicked.');
 });
";
 }
</code></pre>
