Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to insert a php variable into a javascript object/array
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/3613186/what-is-the-safest-way-of-passing-arguments-from-server-side-php-to-client-size">What is the safest way of passing arguments from server-side PHP to client-size JavaScript</a> </p> </blockquote> <p><strong>Goal: Replace the static file name in the javascript object with php data .</strong></p> <p><em>Problem:</em> </p> <p>I don't know if I my syntax or logic is right as I am not getting any js or php errors. Worst of all my script is not giving the desired results. You can see the actual page at <a href="http://www.iamvishal.com/dev/property/burradon-road-burradon" rel="nofollow noreferrer">http://www.iamvishal.com/dev/property/burradon-road-burradon</a> line 197</p> <p><strong>javascript object which I want to make using php:</strong></p> <pre><code>var data = { 'JPEG/1.jpg': { caption: '' }, 'JPEG/2.jpg': { caption: '' }, 'JPEG/3.jpg': { caption: '' }, 'JPEG/4.jpg': { caption: '' }, 'JPEG/5.jpg': { caption: '' }, 'JPEG/6.jpg': { caption: '' }, 'JPEG/7.jpg': { caption: '' }, 'JPEG/8.jpg': { caption: '' },}; </code></pre> <p>So I need to replace JPEG/1.JPG with a php variable $filename. Below is my code.</p> <pre><code>&lt;script type="text/javascript"&gt; var data = { ; &lt;?php $queryglob ="JPEG/*".$node-&gt;field_ropertyid['und'][0]['value'].".jpg"; // Here I am getting all the file names as per my condition. foreach (glob($queryglob) as $filename) { // here I am want each file name to be assigned into the javascript object ?&gt; data = data+'+&lt;?php print $filename ; ?&gt; +':{caption:''}, ; &lt;?php } ?&gt; data = data+}; &lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload