Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing a PHP Variable in external JS file
    text
    copied!<p>I've read lots of thread on here but I am still unable to get a variable passed from PHP to an external JS file and wondered if someone could assist?</p> <p>In my PHP file I have the following;</p> <pre><code>&lt;script type="text/javascript"&gt; var pass_this_variable = &lt;?php $company['website']; ?&gt;; &lt;/script&gt; &lt;script type="text/javascript" src="/js/track.js"&gt;&lt;/script&gt; </code></pre> <p>In the JS file I have the following;</p> <pre><code>document.write('&lt;IFRAME SRC="$company['website']" WIDTH="300" HEIGHT="400"&gt;&lt;/IFRAME&gt;'); </code></pre> <p>What I am trying to achieve is an IFRAME be opened and populated with what is contained within $company['website']. I know I can just use IFRAME directly in the PHP file, but this isn't what I have been tasked with for my homework. When I do use IFRAME directly in the PHP file it works fine, and if I specify a static URL in the JS file such as <a href="http://www.google.com" rel="noreferrer">http://www.google.com</a> this also works fine.</p> <p>Can anyone assist? Thanks</p> <hr> <p>EDIT:</p> <p>Thanks for the answers so far, however I'm still unable to get it working :(</p> <p>The frame that I have in track.php (or track.js) won't load the url thats specified in <code>$company['website']</code>, yet if I change it to <a href="http://www.google.com" rel="noreferrer">http://www.google.com</a> its working fine. For some reason the <code>$company['website']</code> value isn't being passed :(</p>
 

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