title: pass associative array from php to javascript
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/3499757/how-to-pass-an-array-of-strings-from-php-to-javascript-using-ajax">How to pass an array of strings from PHP to Javascript using $.ajax()?</a>  </p>
  </blockquote>
  
  
  
  <p>I want to pass a associative array from php code to javascript code. Please help me. how do I do this ? Is JSON helpful in this matter? If yes then please provide a simple code for help. Thank you. </p>
  
  <p>From comment below:<br/>
  HTML + PHP code </p>
  
  <pre><code>&lt;td&gt; 
      &lt;input type="text" style="width:70;" name="&lt;?php echo $quantity;?&gt;" id="&lt;?php echo $quantity;?&gt;" onkeyup="check_valid_range('&lt;?php echo $itemName;?&gt;','&lt;?php echo $quantity;?&gt;',&lt;?php echo json_encode($product_inventory);?&gt;);"&gt;
  &lt;/td&gt; 
  &lt;script type="text/javascript"&gt; 
      function check_valid_range(product_field, quantity_field, inventory){ 
          var product = document.getElementById(product_field).value; 
          var quantity = document.getElementById(quantity_field).value; 
          var v = inventory[product]; 
          alert(v); 
      } 
  &lt;/script&gt;
  </code></pre>