Here's my problem, I'm trying to make a php variable output into the javascript file. Could I do something like this? <script type="text/javascript" ... > /* ... */ var <?=$text; ?> /* ... */ Code (markup): Will that work?
sure. just name the script file.js.php is what i normally do. and then the first line: <? header('content-type: text/javascript'); ?> PHP:
So can I use a loop to echo javascript data? Now how do I go about using variables? Do I escape the php and put JS there? I'm sorry, but this makes my life so much easier. edit and off topic: you must be some super knowledge filled poster. You joined two months ago and have 200 more posts than me! Wow.
yes, you can echo data from php into a js script ex: You can't walk through PHP arrays or objects in JS code. You can join arrays into strings and use them in Js code : last alert will display 1,2,3
What do you mean "You can't walk through PHP arrays or objects in JS code" Couldn't I just loop through an array using document.write, or something, for each item?