XRS Posted June 23, 2011 Share Posted June 23, 2011 After reading some threads around the net I can't find a situable solutions for this. In my script I want to use a javascript code ( external source from another website ) and there's a JS variable with an ID ( the user ID in the other website). In my script I have the ID stored in the DB and I want to insert it in the javascript by the ID listed in the DB ( that can be changed, so there's the PHP needed ) The JS code: <script> var siteID = 11111; all rest of code </script> How can I change the value of siteID in JS for the one I want? Lets say I would like something like: var siteID = <?php GetOtherSiteID(); ?>; This seems no to be possible. There's any sugestion? Quote Link to comment https://forums.phpfreaks.com/topic/240201-php-inside-javascript/ Share on other sites More sharing options...
HDFilmMaker2112 Posted June 23, 2011 Share Posted June 23, 2011 After reading some threads around the net I can't find a situable solutions for this. In my script I want to use a javascript code ( external source from another website ) and there's a JS variable with an ID ( the user ID in the other website). In my script I have the ID stored in the DB and I want to insert it in the javascript by the ID listed in the DB ( that can be changed, so there's the PHP needed ) The JS code: <script> var siteID = 11111; all rest of code </script> How can I change the value of siteID in JS for the one I want? Lets say I would like something like: var siteID = <?php GetOtherSiteID(); ?>; This seems no to be possible. There's any sugestion? Does the php have line breaks in it? http://www.the-art-of-web.com/php/javascript-escape/ Quote Link to comment https://forums.phpfreaks.com/topic/240201-php-inside-javascript/#findComment-1233830 Share on other sites More sharing options...
ZulfadlyAshBurn Posted June 23, 2011 Share Posted June 23, 2011 It should be possible. Try using ajax. Can you give out more info or scripts. its hard for use to predict what you are trying to do. Quote Link to comment https://forums.phpfreaks.com/topic/240201-php-inside-javascript/#findComment-1233831 Share on other sites More sharing options...
XRS Posted June 23, 2011 Author Share Posted June 23, 2011 No, there's no line breaks. I'ts a simple function that return a number from the DB. In this case, adfly API tool javascript code.. It have a ID you have to use, but another user have another ID. That ID is defined in the DB instead of edit it manually. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/240201-php-inside-javascript/#findComment-1233853 Share on other sites More sharing options...
Andy-H Posted June 23, 2011 Share Posted June 23, 2011 <script> var siteID = <?php echo GetOtherSiteID(); ?>; all rest of code </script> //EDIT If your javascript is stored in an external file, which I shall assume it is not since you used script tags, save it as a php file (.php) and add a javascript content-type header ( header('content-type: text/javascript'); ) and you can run php in the javascript file. Quote Link to comment https://forums.phpfreaks.com/topic/240201-php-inside-javascript/#findComment-1233861 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.