Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Set JavaScript variable from PHP
- http://stackoverflow.com/questions/18189198/ddg#18189336
- If you want to set the variable when the page loads, you could use something like this in the PHP code:
- <script type="text/javascript">var strUser = <?php echo json_encode($someVariable); ?>;</script>
- Just make sure to remove the later variable declaration from the JavaScript.
- If you want to set the variable after the page loads, you'll have to use an AJAX call to ge the value from the server.
- --Joshua Dwire
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement