title: How to get the id of element from php to javascript?
body: <p>im trying to echo out a variable that is written from php using javascript. Well basically I have a drop down menu and what I am trying to do is echo out the number of stocks of the item selected by the user. Here is what I've got so far.</p>
  
  <pre><code>&lt;select id="selectItem" onchange="stock(this)"&gt;
      &lt;?php
       --- connection here ----
      $itemsStock = array();
      $result = mysql_query("SELECT * FROM itemprofile");
      while($row = mysql_fetch_array($result))
          {
              $id = $row['id'];
              $stock = $row['stock'];
              echo '&lt;option value="'.$row['productname'].'" id="'.$row['id'].'"&gt;'.$row['productname'].'&lt;/option&gt;';
              $itemsStock[$id] = $stock;
          }
  
      ?&gt;
  &lt;/select&gt;
  
  Available stock: &lt;div id="stockRemaining"&gt;&lt;/div&gt;
  
  
   &lt;script type="text/javascript"&gt;
  
  var json_arr = &lt;?php echo json_encode($itemsStock);?&gt;;
  var stockValues = JSON.parse(json_arr);
  
      function stock(sel)
      {
          var itemID = sel.value;
          console.log(itemID); // debug to see that you are getting the correct value
          document.getElementById('stockRemaining').innerHTML = stockValues[itemID];
      }
  
  &lt;/script&gt;
  </code></pre>
  
  <p>The convertion of array from php to jquery is fine, i tried echoing it out and it works fine, my problem is the stock() function, I think im doing something wrong on the action inside it cuz everytime I click a different item from the drop down menu, it doesnt show anything at all. Im pretty new to Jscript hope you guys can help me out. Thanks!</p>