title: jquery/Ajax get value of data-id from a text link
body: <p>I have A VERY OLD SCRIPT that I need to modify. You will notice from the code it is using mysql_query() which is outdataed however that is not my issue.</p>
  
  <p>I have a text link in a file named surveycommentslist.php. The link opens a jquery model window that I need to capture a user inputed text in and then save it to a mysql along with the value of the links data-id which tells me which unique user ID to connect the comment to. My issue is I am not able to get the value of data-id using the code I have below.</p>
  
  <p>Here is my code</p>
  
  <pre><code>  &lt;html&gt;
      &lt;head&gt;
      &lt;!-- common scripts --&gt;
      &lt;!-- jQuery library --&gt;
          &lt;script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.2.1/jquery.js"&gt;&lt;/script&gt;
          &lt;!-- jQuery migrate --&gt;
          &lt;script src="js/jquery-migrate-1.2.1.min.js"&gt;&lt;/script&gt;
      &lt;!-- bootstrap framework plugins --&gt;
          &lt;script src="bootstrap/js/bootstrap.min.js"&gt;&lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
      &lt;script&gt;
      $(document).on('click', '.reply', function()
      {
         //get acommentuid
         var val = $(this).attr('data-id');
  
         $.post('surveycommentslist.php', {acommentuid: val}, function(data)
          {
            console.log(data);
          });
      });
      &lt;/script&gt;
  
      &lt;?php
           //lets list comments
            $scommentsql = mysql_query("SELECT * FROM survey_comments 
                         WHERE surveyid=$surveyid  ORDER BY commentdate asc");
            while($scrows = mysql_fetch_array($scommentsql))
              {
                  extract($scrows);
                  $the_comment = stripslashes($the_comment);
                  $commentdate = date("m/d/Y h:ia", strtotime($commentdate));
                  if($touid &gt; 0) { $indent = "margin-left:35px"; }
  
                  //get name of person making the comment
                    $nsql = mysql_query("SELECT fname, lname, userlevel, id AS scommentid FROM users WHERE id=$uid LIMIT 1");
                    $namerow = mysql_fetch_array($nsql);
                    $commenters_fname = stripslashes($namerow['fname']);
                    $commenters_lname = stripslashes($namerow['lname']);
  
                    if($namerow['userlevel'] &gt; 19) 
                      {
                         $adminicon = "&lt;img src='./img/admin_smicon.png' alt='admin'&gt;";
                      }
  
                   echo "&lt;div class='ch-message-item clearfix' style='$indent'&gt;
                             &lt;div class='ch-content'&gt;
                                 $the_comment
                             &lt;/div&gt;
                             &lt;p class='ch-name'&gt;
                                 &lt;strong&gt;$adminicon $commenters_fname $commenters_lname&lt;/strong&gt;
                                 &lt;span class='muted'&gt;$commentdate&lt;/span&gt;";
  
                                 if($touid == 0) 
                                   {
                                      echo " &lt;a href='#switch_modal' class='reply btn btn-default id='$scommentid' btn-small' data-toggle='modal' data-id='$scommentid'&gt;REPLY&lt;/a&gt;";
                                   }
                      echo "&lt;/p&gt;
                         &lt;/div&gt;";
            }
  </code></pre>