RickG Posted October 4, 2013 Share Posted October 4, 2013 hey guys new to the forum i know bits and pieces of programming but i cannot for the life of me get this code working i cannot put the whole code out there for infringment reasons so here is what i can showThanks guys<?phprequire_once (dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'bootstrap.php');$chatroom_id = get_var("id");?><script type="text/javascript">var dc_chatroom_id = <?php echo $chatroom_id = document.getElementById('id'); ?>;<!-- if i take this out ^^^^^ and put just 1 thru 6 one of the chatrooms work i have initially 6 rooms so i need to find a way to make this work. --!></script><div data-role="navbar" data-theme="a"><ul><li id="1"><a href="#room" data-role = 'button' data-transition="fade" data-theme="a">The Hangout</a> </li></ul><ul><li id="2"><a href="#room" data-role = 'button' data-transition="fade" data-theme="a">Electronics Chat</a></li></ul> Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted October 4, 2013 Share Posted October 4, 2013 PHP cannot call javascript functions. PHP is ran on the server and Javascript in the browser. PHP can only output javascript. I think this line var dc_chatroom_id = <?php echo $chatroom_id = document.getElementById('id'); ?>; needs to be var dc_chatroom_id = document.getElementById('<?php echo $chatroom_id; ?>'); Example output of above line would be like the following if $chatroom_id is set to 1 var dc_chatroom_id = document.getElementById('1'); Quote Link to comment Share on other sites More sharing options...
RickG Posted October 4, 2013 Author Share Posted October 4, 2013 yes but i need my php to load all 6 chatrooms due to php only loads once Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted October 4, 2013 Share Posted October 4, 2013 PHP can't do that, it doesn't know what javascript is. You can only get PHP to output the necessary javascript code that loads the chat rooms. You can do a for loop loop that outputs the javascript code needed for the chatrooms eg for($i = 1; $i <= 6; $i++) { // target chatroom echo "var dc_chatroom_id = document.getElementById('$i');"; // load the chatroom echo "javascript_function_that_loads_chatroom(dc_chatroom_id);" } But If you're doing that then you may as well handle this with javascript and not PHP. The above PHP code will output the following javascript code var dc_chatroom_id = document.getElementById('1'); javascript_function_that_loads_chatroom(dc_chatroom_id); var dc_chatroom_id = document.getElementById('2'); javascript_function_that_loads_chatroom(dc_chatroom_id); var dc_chatroom_id = document.getElementById('3'); javascript_function_that_loads_chatroom(dc_chatroom_id); var dc_chatroom_id = document.getElementById('4'); javascript_function_that_loads_chatroom(dc_chatroom_id); var dc_chatroom_id = document.getElementById('5'); javascript_function_that_loads_chatroom(dc_chatroom_id); var dc_chatroom_id = document.getElementById('6'); javascript_function_that_loads_chatroom(dc_chatroom_id); Quote Link to comment 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.