Don't know if this should go in the php forum or javascript, but I can hack around with php a little... know nothing about javascript. But, can I insert a php variable into javascript on the same page? Meaning if I define a variable on a php page as $var=2... then later on the page have some javascript and within that javascript is a variable like "jsvar"... Can I just echo the php variable, $var, within the javascript code where jsvar is defined? In other words, I want jsvar = $var. It would seem like since php is server-side, that the php variable would be inserted into the js code before the js reaches the client... so, in my mind it should work. Does it?
Yes, it should work. I include JS in my PHP scripts all the time You might just use PHP to print out the JS and include your PHP variable directly into the print statement. Or something like that
Enclose the php code in quotes if the variable is a string jsvar = "<?php echo $phpvar;?>" Code (markup):
I use this style: <?=$phpvar?> inside of my javascripts, it does the same thing, just shorter code, and every little bit helps!