Cole001 Posted April 16, 2012 Share Posted April 16, 2012 Hello, I have a php code within a javascript. The javascript gets invoked on button click. The php code withing javascript never gets executed. I don't face the same problem in other browsers. Any help is much appreciated! Regards, Cole Quote Link to comment https://forums.phpfreaks.com/topic/261019-problem-with-php-code-inside-a-javascript/ Share on other sites More sharing options...
l0gic Posted April 16, 2012 Share Posted April 16, 2012 I don't see any code? Quote Link to comment https://forums.phpfreaks.com/topic/261019-problem-with-php-code-inside-a-javascript/#findComment-1337726 Share on other sites More sharing options...
PFMaBiSmAd Posted April 16, 2012 Share Posted April 16, 2012 Php is a server side scripting language. It is executed on the web server when the page is requested. You only get the output that php sends to the browser. Javascript is a client (browser) side scripting language. It is executed after the page is received in the browser. So, there is actually nothing such as php code inside of javascript. In any case, we cannot help you with any of your code unless you post all the code that reproduces the symptom. Quote Link to comment https://forums.phpfreaks.com/topic/261019-problem-with-php-code-inside-a-javascript/#findComment-1337728 Share on other sites More sharing options...
Drummin Posted April 16, 2012 Share Posted April 16, 2012 You can however trick things by writing the JS lines as well to a variable. So say for example you have this that doesn't work. <script type="text/javascript"> url: '{<?php echo $rowpath; ?>}', </script> Try this $path="url: '{$rowpath}',\r"; <script type="text/javascript"> <?php if(isset($path)){echo $path;} ?> </script> At least I've been able to get things to work like this. Quote Link to comment https://forums.phpfreaks.com/topic/261019-problem-with-php-code-inside-a-javascript/#findComment-1337731 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.