I read a lot of threads here, but I still can’t get the variable passed from PHP to an external JS file, and wondered if anyone could help?
In my PHP file, I have the following:
<script type="text/javascript"> var pass_this_variable = <?php $company['website']; ?>; </script> <script type="text/javascript" src="/js/track.js"></script>
In the JS file, I have the following:
document.write('<IFRAME SRC="$company['website']" WIDTH="300" HEIGHT="400"></IFRAME>');
What I'm trying to achieve is to open an IFRAME and populate what is contained in $ company ['website']. I know that I can just use the IFRAME directly in the PHP file, but that’s not what I was assigned to do my homework. When I use the IFRAME directly in the PHP file, it works fine, and if I provide a static URL in the JS file, for example http://www.google.com , it also works fine.
Can anyone help? Thanks
EDIT:
Thanks for the answers so far, however I still can't get it to work :(
The frame that I have in track.php (or track.js) will not load the URL specified in $company['website']
, but if I change it to http://www.google.com it working tone. For some reason, the value of $company['website']
not passed: (
Petra source share