Jump to content

Recommended Posts

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 show

Thanks guys





<?php
require_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>

Link to comment
https://forums.phpfreaks.com/topic/282706-help-with-this-php-and-java-code-please/
Share on other sites

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');

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);
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.