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.
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.
for($i = 0; $i < $numRecords2; $i++){
$prod_id = $_SESSION['prod_array'][$frame_id[$i]];
echo"
$('#frame$frame_id[$i]').click(function() {
$('#top-left-frame').html('<img src=\"$upper_left[$i]\" alt=\"\" />');
$('#top-mid-frame').css('background-image','url($upper_middle[$i])');
$('#top-right-frame').html('<img src=\"$upper_right[$i]\" alt=\"\" />');
$('#mid-left-frame').css('background-image','url($middle_left[$i])');
$('#mid-right-frame').css('background-image','url($middle_right[$i])');
$('#bottom-left-frame').html('<img src=\"$bottom_left[$i]\" alt=\"\" />');
$('#bottom-mid-frame').css('background-image','url($bottom_middle[$i])');
$('#bottom-right-frame').html('<img src=\"$bottom_right[$i]\" alt=\"\" />');
$('#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.');
});
";
}