I'm sorry but I am completely confused about PHP arrays. I read the array section and those two links you posted and I still can't get my code to work. Could you please give me an example of how to transfer a PHP array into a Javascript array. Thanks.
This code is bad...... by for example purposes only; <html><head> <script type="text/javascript"> function parseJS(){ var json=document.getElementById("json_textbox").value; var obj=eval('('+json+')'); for(val in obj){ alert(obj[val]); } } </script></head> <body> <?php $jsa = array(1,2,3,4,5); $json=json_encode($jsa); ?> <form> <input type="hidden" id="json_textbox" value='<?php print $json; ?>' /> <input type='button' value="Do it!" onclick="parseJS();" /> </form> <?print $json; ?> </body></html> Code (markup): Note: This only uses a 2d array, you will need to process it differently as passing an array of hashes will create a JS object (which, technically everything is in js anyway).... --> You could also process the JS inline within php tags in the JS function depending on the requirement of your JS..... --> As mentioned previously, You also have interchangeability by using serialize, which is the better option depending on the scope of your project and if the data is likely to be used/needs to be used elsewhere.....