var to = "<?php echo $to; ?>";
or remove echo and leave just short tag/echo shortcut like that:
var to = "<?= $to; ?>";
Also, you are trying to use php in .js file. Make sure your server is configured to parse .js as it was php. Even better, change js into php. If you have lot of js code, you can define js variables in your view file, and include your js file at the bottom of your page.
Notice, that short tags have to be turned on in php.ini for that to work (as of php 5.3, 5.4 will allow for short echo even with short tags turned off) and that’s not common on shared hosting servers.
freeyii, as I wrote in my first post, and as sensorario stated right above, make sure php actually parses your file. It would be really helpful if you wrote what you actually tried to do to solve your problem instead of bumping up your thread… Once again:
Did your tried moving your js code to php file ? Did you look into documentation? CClientScript has some nice functions which can help you:
You can use first one to include variables you echo from php to js in .php file, and second function to include js file where variables set before will be used…