Possible Duplicate:
Pass a PHP string to a Javascript variable (and escape newlines)
I’m working on a project and it’s already done, but it needs one more midification and its applying language constants in javascript files.
consider we include a javascript file and in that we have something like this
alert("YOU Have VOTED BEFORE");
easy like that , the script will alert that text
but what if we need to alert a language constant of it :
alert("<?php echo _VOTED_BEFORE?>");
this will be worked only if echo the script like inline of my php codes …
but, how can we read and include php constants or $vars for a outside JavaScript file ???
There is a way of doing this using a query string in the script path
See my answer here
How to pass variable from php template to javascript
Unfortunately this will break the cache for your js file so weight your options first
for the sake of not writing too much code refer to the link to see how to retrieve the value