How can I pass a PHP variable value to javascript?
|
closed as not a real question by aaronasterling, Joel Etherton, Boris Guéry, AlexanderMP, Christopher Orr Feb 7 '11 at 20:53
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.
|
|||||
|
Never pass a variable like @Goran Jovic or @KomarSerjio suggested. It's asking for a trouble. Use JSON (
This guarantees that no error will occur. |
|||||||
|
In your PHP code, which outputs HTML, in the
|
||||
|
you need to understand the meaning of "server-side" and "client-side". basically, the php is "generating" the output for the browser (and the js is just part of that output) so in order to "pass variable from php to js" all you need to do is just "echo" the js variable:
|
|||
|