title: Using PHP Variable as ID and calling from Javascript
body: <p>Im using this is an ID</p>
  
  <pre><code> $id = $row['id'];
   echo "&lt;input type='text' id='$id' value='$row["s_code"]'&gt;";
  </code></pre>
  
  <p>How can I get that ID in javascript function? I want it in here...</p>
  
  <pre><code> var scode  = $('#').val();
  </code></pre>
  
  <p>While loop..</p>
  
  <pre><code>    while ($row = mysqli_fetch_array($sqlSimplex , MYSQLI_ASSOC)) {
          echo "&lt;tr&gt;&lt;td&gt;";
          $id = $row['id'];
          echo "&lt;input type='text' id='$id' value='".$row['s_code']."' readonly&gt;";
          echo "&lt;/td&gt;&lt;td&gt;";
          echo $row['description'];
          echo "&lt;/td&gt;";
          echo "&lt;input type='hidden' id='comval'  value='$newProductID'&gt;";
          echo "&lt;td&gt;";
          echo "&lt;input type='text' size='7' id='userqtyval'&gt;";
          echo "&lt;/td&gt;&lt;td&gt;";
          echo "&lt;input type='button' onclick='addthis()'  value='Add!'&gt;";
          echo "&lt;/td&gt;&lt;/tr&gt;";  
  
      }
  </code></pre>
  
  <p>Javascript </p>
  
  <pre><code>  function addthis() {
  
              var myID = '$id';
              var scode = $("#"+myID).val();
  
  
              alert(scode);
                  $.ajax({
                      type: 'POST',
                      url: 'insertsimplextoc_comp.php',
                      data: { simplexcode: scode },
                  }); 
      }
  </code></pre>
  
  <p>Been stuck on this for over a week!</p>