It can get a little confusing sometimes creating JavaScript from PHP because you are creating a script within a script.
But basically once you get used to the idea it's not so hard...
You understand the basic concepts and sytax structure of JavaScript? If so, you will know you create variables similarly to PHP in JavaScript.
Your php script just has to output the appropriate text to create the variable...
here's an example:
<script language="JavaScript">
var sVariable = <? echo "\"" . $phpVariable . "\";"; ?>
</script>
Now, notice that I echoed the extra " characters to enclose the phpVariable, as the JavaScript variable I was creating is a String. You have to take extra care when generating JavaScript from php, as it is easy to get confused with which is what, and can easily end up with syntax errors.
Now, what if I knew my $phpVariable may contain " characters? It would of course break the JavaScript string. So you would have to replace all " with \" in $phpVariable so as not to enduce a JavaScript error.
Just keep things like that in mind when generating JavaScript, and you'll see it's really not all that difficult.
k, good luck man
-Adam 🙂