Jump to content

pass php array into javascript function as parameter


shakeelstha

Recommended Posts

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>";

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.