Last Updated: February 25, 2016
·
6.436K
· teknonono

Access php variable from external js file

First in your test.php file
$phpVar = 'from php';
echo "<script type="text/javascript">var jsVar = " $phpVar ";</script>";
echo "<script type="text/javascript" src="external.js"></script>";
Then use it in .js file
alert( jsVar );