MyBB Community Forums

Full Version: add javascript in the "username"
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
why I added the javascript does not work?
I want to add "javascript PopupMenu" right when username is clicked
I add this code in the "postbit templates" in the "username"
<a id="username_tools" href="#" class="user-info">{$post['profilelink']}</a>
<div id="username_tools_popup" class="popup_menu" style="display: none; position: absolute; z-index: 100; top: 354px; left: 163px; visibility: visible;">
	<div class="popup_item_container">
		<a class="popup_item" href="{$post['profilelink_plain']}">{$lang->viewprofile}</a>
	</div>
	<div class="popup_item_container">
		<a class="popup_item" href="private.php?action=send&amp;uid={$post['uid']}">{$lang->sendpm}</a>
	</div>
	<div class="popup_item_container">
		<a class="popup_item" href="search.php?action=finduserthreads&amp;uid={$post['uid']}">{$lang->viewthreads}</a>
	</div>
    	<div class="popup_item_container">
		<a class="popup_item" href="member.php?action=emailuser&amp;uid={$post['uid']}">{$lang->sendemail}</a>
	</div>
    	<div class="popup_item_container">
		<a class="popup_item" href="search.php?action=finduser&amp;uid={$post['uid']}">{$lang->viewposts}</a>
</div>
<script type="text/javascript">
// <!--
    if(use_xmlhttprequest == "1")
    {
        new PopupMenu("username_tools");
    }
// -->
</script>
1.You don't have unique identifier for your id tag (ID tag can't have the same value)
2.{$post['profilelink']} contains <a href=""></a> tag to profile username, you need to use variable that displays plain profile ( {$post['username_formatted']} )
3.position is calculated after firing that event ,there's no need for "position: absolute; z-index: 100; top: 354px; left: 163px; visibility: visible;">


<a id="username_tools_{$post['pid']}" href="#" class="user-info">['username_formatted']} </a>



<div id="username_tools_{$post['pid']}_popup" class="popup_menu" style="display: none;">
     <div class="popup_item_container">
         <a class="popup_item" href="{$post['profilelink_plain']}">{$lang->viewprofile}</a>
     </div>
     <div class="popup_item_container">
         <a class="popup_item" href="private.php?action=send&amp;uid={$post['uid']}">{$lang->sendpm}</a>
     </div>
     <div class="popup_item_container">
         <a class="popup_item" href="search.php?action=finduserthreads&amp;uid={$post['uid']}">{$lang->viewthreads}</a>
     </div>
         <div class="popup_item_container">
         <a class="popup_item" href="member.php?action=emailuser&amp;uid={$post['uid']}">{$lang->sendemail}</a>
     </div>
         <div class="popup_item_container">
         <a class="popup_item" href="search.php?action=finduser&amp;uid={$post['uid']}">{$lang->viewposts}</a>
 </div>

<script type="text/javascript">
 // <!--
     if(use_xmlhttprequest == "1")
     {
         new PopupMenu("username_tools_{$post['pid']}");
     }
 // -->
 </script>
what should I do?
I just wanted if "username" in the click will appear "PopupMenu" the details
Try with the content in #2 post.
This is the code that I use now
<div class="user-info">
<a id="username_tools_{$post['pid']}" href="#">{$post['username_formatted']}</a>
<div id="username_tools_{$post['pid']}_popup" class="popup_menu" style="display: none;">
     <div class="popup_item_container">
         <a class="popup_item" href="{$post['profilelink_plain']}">{$lang->viewprofile}</a>
     </div>
     <div class="popup_item_container">
         <a class="popup_item" href="private.php?action=send&amp;uid={$post['uid']}">{$lang->sendpm}</a>
     </div>
     <div class="popup_item_container">
         <a class="popup_item" href="search.php?action=finduserthreads&amp;uid={$post['uid']}">{$lang->viewthreads}</a>
     </div>
         <div class="popup_item_container">
         <a class="popup_item" href="member.php?action=emailuser&amp;uid={$post['uid']}">{$lang->sendemail}</a>
     </div>
         <div class="popup_item_container">
         <a class="popup_item" href="search.php?action=finduser&amp;uid={$post['uid']}">{$lang->viewposts}</a>
</div>

<script type="text/javascript">
// <!--
     if(use_xmlhttprequest == "1")
     {
         new PopupMenu("username_tools_{$post['pid']}");
     }
// -->
</script>
</div>
look after the click does not widen
see the attachment below
what should i do Huh
the language variables you are using are not available at this point in teh code so there is no text to push the window wider. replace the $lang->XXX bits with regular text and it should work. Otherwise you need to edit the core to get those language variables loaded.
okay
thank you all
I have understood the problem Big Grin
correct, the language variables you are trying to output are not available when you are calling them. You need to edit the template to use actual text or edit the build_postbit function to load the language files that contain the variables you want.
okay
thank you "Johnny S"
thank you too uncle "pavemen" Big Grin
maybe I was sleepy so do not think about it Sleepy