Is it possible to pass a php variable to a javascript function? If so, please give an example. thanks
What you should do is echo it: <? $x = 'hai!'; echo "<script>var x = '" . $x . "';</script>"; ?> Code (php): Returns: <script>var x = 'hai!';</script>
Thanks, that works if the php codes are in the same file as the javascript. Ok what I want to do is to reference a php variable ($filename) in a js function. But..... I want to do that without running the php file, or maybe load it in the background if possible. Hope that make sense. If you can help with this problem Im happy to give you a permanent link on my site. Thanks
Kasapa said: Yes, this is nice. And he can do it like that: And at the end of the php file "echo $var;" You will need to convert your current html page to php to get php work on it. If you don't want to rename it to .php extension, check this tip: run php script in html page Good luck !
there's no button..and don't want to add a button on the middle of the page. Ok basically my site is image hosting. The image file name variable is in upload.php and it's called $filename. Because I'm using Flash to upload and upload.php will never be loaded by the browser, it's used by the Flash script ONLY. After the images are uploaded I want to somehow pass the variable $filename to the js script.