mike12255 Posted October 5, 2011 Share Posted October 5, 2011 <javascript> <php code inside javascript> </javascript> <php> </php> What I am asking is if the php code inside the javascript function will be executed only when the javascript function is called even though the page is already loaded? Quote Link to comment https://forums.phpfreaks.com/topic/248494-does-phpjavascript-work-this-way/ Share on other sites More sharing options...
PFMaBiSmAd Posted October 5, 2011 Share Posted October 5, 2011 Nope. The php code is executed on the web server when the page is requested. Only the output from the php code would exist inside the javascript when the javascript is executed in the browser. What exact problem are you trying to solve? Quote Link to comment https://forums.phpfreaks.com/topic/248494-does-phpjavascript-work-this-way/#findComment-1276100 Share on other sites More sharing options...
mike12255 Posted October 5, 2011 Author Share Posted October 5, 2011 I want to auto populate a select field based on the option chosen from the select field above it. Quote Link to comment https://forums.phpfreaks.com/topic/248494-does-phpjavascript-work-this-way/#findComment-1276102 Share on other sites More sharing options...
joe92 Posted October 5, 2011 Share Posted October 5, 2011 You would use ajax for this. Quote Link to comment https://forums.phpfreaks.com/topic/248494-does-phpjavascript-work-this-way/#findComment-1276105 Share on other sites More sharing options...
mike12255 Posted October 5, 2011 Author Share Posted October 5, 2011 i tried (http://www.phpfreaks.com/forums/index.php?topic=345067.0) but I couldnt get it to work. Quote Link to comment https://forums.phpfreaks.com/topic/248494-does-phpjavascript-work-this-way/#findComment-1276109 Share on other sites More sharing options...
joe92 Posted October 6, 2011 Share Posted October 6, 2011 This is a fairly OK tutorial on GET and POST requests via ajax: http://www.javascriptkit.com/dhtmltutors/ajaxgetpost.shtml You would make the ajax call from your javascript to go to xyz.php script. In there you grab what you sent and then treat it like any other php script doing mysql querys, for loops etc.. At the end of the php echo what you need to return and that will be the responseText in the javascript. Using this responseText, manipulate the page using javascript to show what you need to show. Quote Link to comment https://forums.phpfreaks.com/topic/248494-does-phpjavascript-work-this-way/#findComment-1276377 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.