> 
> **Possible Duplicate:**  
> 
> [How to pass an array of strings from PHP to Javascript using $.ajax()?](https://stackoverflow.com/questions/3499757/how-to-pass-an-array-of-strings-from-php-to-javascript-using-ajax) 
> 
> 
> 

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. 

From comment below:  

```
<td> 
    <input type="text" style="width:70;" name="<?php echo $quantity;?>" id="<?php echo $quantity;?>" onkeyup="check_valid_range('<?php echo $itemName;?>','<?php echo $quantity;?>',<?php echo json_encode($product_inventory);?>);">
</td> 
<script type="text/javascript"> 
    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); 
    } 
</script>

```