473,395 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

tooltip alignment

omerbutt
638 512MB
hi there i have a link in my pge and on mouseover i want to show the tooltip by getting the coordinates x and y from the screen where the onmouseover event occoured can any one teell me the way to get the right coordinates in
IE and FF my code is not working properly or say it is not a generic code that i could reuse it has the positioning problem so in all my sites where i have to use the tooltip i have to position is manually on that page ....although it gives me correct out put if i make link on a blank page and try to hover it i get the exact position of the tooltip right under my mouse but when i try to embed into my page its all a fussssss and i have to add up some pixels manually to do that and yes i have to swap the x and y coordinates to position the tooltip menas in normal blank page i use
Expand|Select|Wrap|Line Numbers
  1. prevWin.style.top= parseInt(yPos)+'px';
  2. prevWin.style.left= parseInt(xPos)+20+'px';
  3.  
but when i copy paste the same code into my page it starts to display the tooltip on the top and i have to omit the top and assign the xPos to left only
Expand|Select|Wrap|Line Numbers
  1. prevWin.style.left = parseInt(xPos)-300+'px';
  2.  
how stupid can any one help me i am tired of looing on to available tooltip i have to make my own ,here is my code
file:tooltip.js
Expand|Select|Wrap|Line Numbers
  1. var xhr = false;
  2. var xhr = false;
  3. var xPos,yPos;
  4. var xhr;
  5. function showPreview(evt,id,diff){
  6. getPreview(evt,id,diff);
  7.                  return false;
  8.             }
  9.         function hidePreview(){
  10.          document.getElementById("previewWin"). style.visibility = "hidden";
  11.         }
  12.         function hidePreview_m(){
  13.                  document.getElementById("previewWin_m"). style.visibility = "hidden";
  14.             }
  15.         function getPreview(evt,id,diff){
  16.             if (evt){
  17.                 var url = evt.target;
  18.             }
  19.             else{
  20.                 evt = window.event;
  21.                 var url = evt.srcElement;
  22.             }
  23.             alert(evt.srcElement);
  24.             //my added
  25.             if(diff=="mold"){
  26.                 url = "ajax/mold_tip.php?item_name="+id;
  27.             }else{
  28.                 url = "ajax/tooltip_temp.php?item_name="+id;
  29.             }
  30.             //my added
  31.             xPos = evt.clientX;
  32.             yPos = evt.clientY;
  33.             if (window.XMLHttpRequest){
  34.                 xhr = new XMLHttpRequest();
  35.             }
  36.             else {
  37.                 if(window.ActiveXObject){
  38.                    try {
  39.                       xhr = new ActiveXObject ("Microsoft.XMLHTTP");
  40.                    }
  41.                    catch(e){ }
  42.                 }
  43.             }
  44.              if(xhr){
  45.                 if(diff!="mold"){
  46.                     xhr.onreadystatechange = showContents;
  47.                     xhr.open("GET", url, true);
  48.                     xhr.send(null);
  49.                 }else{
  50.                     xhr.onreadystatechange = showmolds;
  51.                     xhr.open("GET", url, true);
  52.                     xhr.send(null);
  53.                 }
  54.              }
  55.              else {
  56.                 alert("Sorry, but I couldn't create an XMLHttpRequest");
  57.              }
  58.         }
  59.         function showmolds(){
  60.              var prevWin = document.getElementById ("previewWin_m");
  61.              hidePreview();
  62.              if(xhr.readyState==4){
  63.                 var innerHtml;
  64.                 var a=(xhr.status==200) ? xhr.responseText : "There was a problem with the request " + xhr.status;
  65.                 innerHtml=a;
  66.                 prevWin.innerHTML=innerHtml;
  67.                 prevWin.style.top='0px';
  68.                 prevWin.style.top= parseInt(yPos)+170+'px';
  69.                 prevWin.style.left= parseInt(xPos)+20+'px';
  70.                 prevWin.style.visibility = "visible";
  71.              }
  72.         }
  73.         function showContents(){
  74.                  var prevWin = document.getElementById ("previewWin");
  75.                  hidePreview_m();
  76.                  if(xhr.readyState==4){
  77.                     var innerHtml;
  78.                     //innerHtml='<div class="floater tip_close" onclick="hidePreview()"></div>';
  79.                     var a=(xhr.status==200) ? xhr.responseText : "There was a problem with the request " + xhr.status;
  80.                     innerHtml=a;
  81.                     prevWin.innerHTML=innerHtml;
  82.                     prevWin.style.top= parseInt(yPos)+170+'px';
  83.                     prevWin.style.left= parseInt(xPos)+20+'px';
  84.                     //prevWin.style.top = parseInt(xPos)+2+'px';
  85.                     //prevWin.style.left = parseInt(xPos)-300+'px';
  86.                     prevWin.style.visibility = "visible";
  87.                     //prevWin.onmouseout = hidePreview;
  88.                  }
  89.             }
  90.  
file:tooltip.css
Expand|Select|Wrap|Line Numbers
  1. #previewWin {
  2.      width:440px;
  3.      height:auto;
  4.      position: absolute;
  5.      visibility: hidden;
  6.      overflow: hidden;
  7.      cursor:pointer;
  8. }
  9. #previewWin_m{
  10.      width:440px;
  11.      height:auto;
  12.      position: absolute;
  13.      visibility: hidden;
  14.      overflow: hidden;
  15.      cursor:pointer;
  16. }
  17.  
file:index.php
Expand|Select|Wrap|Line Numbers
  1. <table cellspacing="0" cellpadding="0" align="center" border="0" width="981">
  2. <tr>
  3.                                                                         <td align="left" valign="middle" colspan="2"><table width="100%" border="0" cellspacing="0" cellpadding="0" class="detail_bg">
  4.                                                                           <tr>
  5.                                                                             <td><span class="text_white_18_bold">&nbsp;&nbsp;DETAILS:</span><span class="text_white_11"><strong><a href="#." style="cursor:pointer; text-decoration:none;" class="text_white_11" onmouseover="showPreview(event,'<?=$design_info['design_mould'];?>','mold')"><?=$design_info['design_mould']?></a> with 
  6.                                                                             <?
  7.                                                                                     $link_1="";
  8.                                                                                     $link_2="";
  9.                                                                                     $link_3="";
  10.                                                                                     $link_4="";
  11.                                                                                     $first=explode(",",$design_info['design_special_adons']);
  12.                                                                                     $f_a_1=$first[0];
  13.                                                                                     $f_a_2=$first[1];
  14.                                                                                     $f_a_3=$first[2];
  15.                                                                                     $f_a_4=$first[3];
  16.                                                                                     if($f_a_1){
  17.                                                                                         $link_1="<a href=\"#.\" class=\"text_white_11\" onmouseover=\"showPreview(event,'$f_a_1','')\">$f_a_1</a>";
  18.                                                                                     }
  19.                                                                                     if($f_a_2){
  20.                                                                                         $link_2="<a href=\"#.\" class=\"text_white_11\" onmouseover=\"showPreview(event,'$f_a_2','')\">$f_a_2</a>";
  21.                                                                                     }
  22.                                                                                     if($f_a_3){
  23.                                                                                         $link_3="<a href=\"#.\" class=\"text_white_11\" onmouseover=\"showPreview(event,'$f_a_3','')\">$f_a_3</a>";
  24.                                                                                     }
  25.                                                                                     if($f_a_4){
  26.                                                                                         $link_4="<a href=\"#.\" class=\"text_white_11\" onmouseover=\"showPreview(event,'$f_a_4','')\">$f_a_4</a>";
  27.                                                                                     }
  28.                                                                                 ?>
  29.                                                                             <?=$link_1; if($link_2<>""){ echo ", ".$link_2;}?> </strong></span></td>
  30.                                                                           </tr>
  31. </table>
  32. <div id="previewWin"></div>
  33. <div id="previewWin_m"></div>
  34.  
regards omer
Sep 10 '08 #1

✓ answered by Dormilich

ok, a simple sample:
Expand|Select|Wrap|Line Numbers
  1.     var elem = document.getElementById(_element_id_);
  2.     elem.setAttribute("title", _text_from_ajax_);
note: entities inside the text are not rendered, but since javascript uses unicode natively, you can convert them before returning the request to the javascript.

5 2505
Dormilich
8,658 Expert Mod 8TB
you could use the title attribute.... works even with javascript turned off

regards
Sep 10 '08 #2
omerbutt
638 512MB
you could use the title attribute.... works even with javascript turned off

regards
ineed to use ajax cause the content loaded is dyanamic could be changed after wards i have to do it this way and how can i postion the div by using title only ????????
regards ,
omer
Sep 10 '08 #3
Dormilich
8,658 Expert Mod 8TB
as I understand it, you want a tooltip over a special element (using its id) and there seems to be only a text message...

I still would use title attribute because
- you can dynamically create/remove it (createAttribute())
- it shows whenever (and wherever) the mouse hovers over that element (no need of an event at all)
- you can change the content to your liking

regards
Sep 10 '08 #4
omerbutt
638 512MB
as I understand it, you want a tooltip over a special element (using its id) and there seems to be only a text message...

I still would use title attribute because
- you can dynamically create/remove it (createAttribute())
- it shows whenever (and wherever) the mouse hovers over that element (no need of an event at all)
- you can change the content to your liking

regards
can you give an example or alink to any page that can show how tomake that simple tooltip working
regards,
omer
Sep 10 '08 #5
Dormilich
8,658 Expert Mod 8TB
ok, a simple sample:
Expand|Select|Wrap|Line Numbers
  1.     var elem = document.getElementById(_element_id_);
  2.     elem.setAttribute("title", _text_from_ajax_);
note: entities inside the text are not rendered, but since javascript uses unicode natively, you can convert them before returning the request to the javascript.
Sep 10 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Yves Royer | last post by:
Hi, I'm currently writing an application (in VS 2005 bèta 2) and made some own user controls. In each user control I added a ToolTip object so i can set some tooltips on checkboxes etc. What...
0
by: Yves Royer | last post by:
Hi, My first post didn't show up so here's a second try. I'm currently writing an application (in VS 2005 bèta 2) and made some own user controls. In each user control I added a ToolTip object...
6
by: ltt19 | last post by:
HI everyone, So, I have many buttons, and all of them must show a tooltip with the same string, except one word, that I must read this owrd from a variable. Although, the "ToolTip on x" property...
0
by: EricL | last post by:
Hello, I have written a Custom Control which inherits from ToolTip and it is an OwnerDraw tooltip. In the Popup event I calculate the size of the tooltip I need to display (rather large...
5
by: =?Utf-8?B?cGV0ZTE5Njk=?= | last post by:
I use Visual Studio 2005 and created a very simple Form with one button. I added a Tooltip for that button. It shows fine the first time I hover over that button. But if I let it disappear by the...
6
by: john | last post by:
I have the following textbox setup with Text & ToolTip Bindings as follows; I'm using Visual Studio 2008 VB: <asp:TextBox ID="txtDay1" runat="server" Text='<%# Eval("Day1") %>'...
3
omerbutt
by: omerbutt | last post by:
hi there i have downloaded a prototype tooltip from http://www.nickstakenburg.com/projects/prototip/ the logic it uses is to call the script after creating the <div> for example i am using the...
0
omerbutt
by: omerbutt | last post by:
hi there i have tried to make my own AJAX tooltip it works all right and every things fine and the tooltip display right under the element i want to display untill unless i switch my resolution, it...
16
by: Charles Law | last post by:
I have to take this personally now. Tooltips have been flakey since the dawn of .NET, but to still have to put up with a disappearing tooltip in VS 2008 is getting beyond a joke. Tooltips have...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.