shakeelstha Posted March 9, 2008 Share Posted March 9, 2008 I have a php array. I need to pass it to the javascript function as parameter. Within the javascript function it should work as javascript array not php array..How can I do that? Quote Link to comment Share on other sites More sharing options...
Xajel Posted March 9, 2008 Share Posted March 9, 2008 you have to echo the array using normal JS array making example $myarray = array("value1", "value2", "value3", etc..); echo "<script language=\"javascript\">"; echo "var jarray = array();"; for ($i=0; $i<count($myarray); $i++) { echo "jarray[$i] = '$myarray[$i]';\n; } echo "</script>"; Quote Link to comment Share on other sites More sharing options...
shakeelstha Posted March 10, 2008 Author Share Posted March 10, 2008 This is not what I am looking for. I need to pass the whole php array into javascript function as parameter. Not just converting php array into javascript array......................the actual parameter should be in php array and the referenced parameter should be in javascipt array. Quote Link to comment Share on other sites More sharing options...
Xajel Posted March 10, 2008 Share Posted March 10, 2008 well, other than what I said before, this is not possible PHP is server-side script, so only the server will handle it's enviroment javascript is client-side script, and only the client will handle it's enviroment the server is not able to handle the javascript, and the client is not able to handle PHP script, so you're limited to echo the array like the above example Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.