jQuery How do I call current/correct value after popup
<p>Basically I have a list of files composed from a foreach loop that all have the same code except for the name, which carries the file_id for each file. My problem is that when I added an on-click pop-up event I lose the ability to fetch the current <code>$(".flag")</code> attribute name. Is there a way that I can pass it along the way so I can use it in the end?</p>

<p>PHP: (the user sees the link which they can click...remember there are several of these as a result from the foreach loop. I'm showing one for example)</p>

<pre><code>echo "&lt;td&gt;&lt;a href='#' class='flag' name='$files[id]' &gt;Click Here&lt;/a&gt;  ( $files[nums] )&lt;/td&gt;";
</code></pre>

<p>jQuery: (on-click this will happen)</p>

<pre><code>$(".flag").live('click', function() {
    $(".pop").show("slow"); 
    return false;
});
</code></pre>

<p>HTML: this div will popup</p>

<pre><code>&lt;div class="pop"&gt;
      &lt;form method="post" id="new_folder" &gt;
          &lt;p&gt;&lt;label for="folder"&gt;Reason for Reporting?&lt;/label&gt;&lt;textarea id="report_reason" name="report_reason" maxlenght="100" style="resize:none" cols="30" rows="5"&gt;Please limit your response to 100 characters.&lt;/textarea&gt;&lt;/p&gt;
          &lt;p&gt;&lt;input type="submit" value="Submit" id="message_submit"/&gt; or &lt;a class="close" href="/"&gt;Cancel&lt;/a&gt;&lt;/p&gt;
      &lt;/form&gt;
  &lt;/div&gt;
</code></pre>

<p>jQuery: on submit I need to send the current <code>$files['id']</code> and textarea value via ajax. The textarea sends the correct data, but the <code>$(".flag")</code> instead of being the id of the selected link it is the id of the first fetched id from the foreach loop</p>

<pre><code>$("#message_submit").on("click", function(e){
      var fileID = $(".flag").attr("name");
      var text = $("#report_reason").val();
      $(".pop").hide("slow"); 

      $.ajax({
              url: '&lt;?php echo base_url().'home/report_file';?&gt;', 
              type: 'POST',
              data: { val: fileID, val2: text },
              dataType: 'json', 
              success: function(output_string){
                  $(".success").text("You have flagged this file!!").show().css({"color" : "green", "margin-top" : "10px"});
                  $(".success").fadeOut(10000);   
              }
      });
      return false;
});
</code></pre>
