Gutspiller Posted September 22, 2011 Share Posted September 22, 2011 Here is my current code. <?php echo " <script type=\"text/javascript\"> <!-- var containerID = \"advertise\"; var number = 16; var timerID = setInterval(\"CountdownTimer()\",1000); function CountdownTimer() { if(number > 1) { number--; ReplaceContentInContainer(containerID,number); } else { clearInterval(timerID); ReplaceContentInContainer(containerID,'<p class=\"downbutton\"><a href=\"download.php?shortURL=$filedrop->shortURL\" class=\"uploadbutton round-tl-br-xl green-matte\">Download</a></p>'); } } //--> </script> "; ?> This works in the page I have it on, but I am trying to instead of showing all that in the source, have it show something like <script type="text/javascript" src="dbutton.js"></script> The problem is that the php variable $filedrop->shortURL isn't being processed when I move it all over to its own js file. It writes out "$filedrop->shortURL" instead. I don't know much at all about javascript, other than looking at code and stumbling my way through it. Can somebody rewrite this code as to how I should insert it into my dbutton.js file to make it still work with that php variable? Thanks in advanced for any help you can offer me. Quote Link to comment https://forums.phpfreaks.com/topic/247632-calling-php-var-in-javascript/ Share on other sites More sharing options...
trq Posted September 22, 2011 Share Posted September 22, 2011 You would need to configure your server to parse *.js files as php. Quote Link to comment https://forums.phpfreaks.com/topic/247632-calling-php-var-in-javascript/#findComment-1271651 Share on other sites More sharing options...
PFMaBiSmAd Posted September 22, 2011 Share Posted September 22, 2011 or you can use a .php file extension, but you need to output a correct Content-type: header at that start of the code in the file so that it will be treated as javascript. Quote Link to comment https://forums.phpfreaks.com/topic/247632-calling-php-var-in-javascript/#findComment-1271652 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.