MyBB Community Forums

Full Version: Variables in Link
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello

The following code works fine within MyBB pages/templates. I have created my own personal index page and the link when highlighted to enter the chatroom shows up as the variables and not the info required.

<!-- PRO CHAT ROOMS  -->
<script language="JavaScript">
<!-- 
var userName = "{$mybb->user['username']}";
var userID = "{$mybb->user['uid']}";
var roomID = "Welcome!";
// -->
</script> 
<script language="JavaScript" type="text/javascript" src="/prochatrooms/chat.js"></script> 

<a href="javascript:launchChat();">Chatrooms</a>

So when people click on the link to enter the room, there nickname is {$mybb->user['username']} which is obviously wrong.

How do I get it to understand and change the variable to the correct username?
Remove the brackets, making it like so:

$mybb->user['username']
Thank you! :-)
You're welcome Knerba! Smile
Oops, sorry just realised that it doesn't work, the only thing is does it takes the brackets out of the name when logged into the chat.

In the address bar of the popup, the variables show... but without the brackets.
Try this:

<!-- PRO CHAT ROOMS  -->
<script language="JavaScript">
<!-- 
var userName = "'.$mybb->user['username'].'";
var userID = "'.$mybb->user['uid'].'";
var roomID = "Welcome!";
// -->
</script> 
<script language="JavaScript" type="text/javascript" src="/prochatrooms/chat.js"></script>
Tried that, just enters the room with the full stops.

I'm starting to think maybe because it is not written in php that it doesn't understand where to the values for the variables?
That's weird. I tried using the same variable (exactly as you first tried it) in a script block and it works.

Are you sure that chat room script is calling the variable correctly? Also, can we have the URL to your forum?
Sure, it's http://www.frogga.co.uk
Anybody? Bumping

Anybody? Bumping! Big Grin