473,405 Members | 2,310 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,405 software developers and data experts.

Cross-browser onmouseover on select.options

Hello,

I'm trying to make different tooltips appear as the mouse moves over the various options of a select. I found a slick method for doing so in mozilla-based browsers, but IE chokes on it.

Any help for making this work in IE would be very much appreciated.

Here's the code I found:

Expand|Select|Wrap|Line Numbers
  1.  <HEAD> 
  2. <STYLE>
  3. #tooltip {
  4. position: absolute;
  5. visibility: hidden;
  6. border: 1px solid black;
  7. background-color: lightyellow;
  8. }
  9. </STYLE>
  10. <SCRIPT>
  11. var descriptions = {
  12. '1': 'This is number 1.',
  13. '2': 'This is number 2.',
  14. '3': 'This is number 3.'
  15. }
  16. function showTooltip (nextTo, tip) {
  17. var tt = document.getElementById('tooltip');
  18. tt.innerHTML = descriptions[tip];
  19. tt.style.left = (getPageLeft(nextTo) + nextTo.offsetWidth) + 'px';
  20. tt.style.top = getPageTop(nextTo) + 'px';
  21. tt.style.visibility = 'visible';
  22. function hideTooltip () {
  23. document.getElementById('tooltip').style.visibility = 'hidden';
  24. function getPageLeft (el) {
  25. var left = 0;
  26. do 
  27. left += el.offsetLeft;
  28. while ((el = el.offsetParent));
  29. return left;
  30. }
  31. function getPageTop (el) {
  32. var top = 0;
  33. do 
  34. top += el.offsetTop;
  35. while ((el = el.offsetParent));
  36. return top;
  37. }
  38. </SCRIPT>
  39. </HEAD>
  40. <BODY>
  41. <DIV ID="tooltip"></DIV>
  42. <SELECT ID="aSelect"
  43. ONMOUSEOVER="showTooltip(this, event.target.value)"
  44. ONMOUSEOUT="hideTooltip();"
  45. >
  46. <OPTION VALUE="1">1
  47. <OPTION VALUE="2">2
  48. <OPTION VALUE="3">3
  49. </SELECT>
  50.  
  51. </BODY>
  52.  
Thanks in advance,

jj
Feb 23 '07 #1
11 18924
acoder
16,027 Expert Mod 8TB
See this page
Feb 23 '07 #2
Thank you, but unfortunately my knowledge level is not high enough that I could get this from the page you reference.

The part of the script that IE is choking on is the event argument in the onmouseover on the select itself, shown here:

<SELECT ID="aSelect"
ONMOUSEOVER="showTooltip(this, event.target.value)"
ONMOUSEOUT="hideTooltip();"
>


Apparently IE doesn't know what to do with that. Any suggestions on how I might work around that?

Thank you, again,

jj
Feb 23 '07 #3
acoder
16,027 Expert Mod 8TB
Read from this part. For IE, you need to use event.fromElement instead of relatedTarget (which is W3C).
Feb 23 '07 #4
Hi,

event.fromElement doesn't work either for this case

any advice?
Mar 27 '07 #5
acoder
16,027 Expert Mod 8TB
Hi,

event.fromElement doesn't work either for this case

any advice?
Post your code.
Mar 27 '07 #6
it is almost the same code as above, only i changed/add :

Expand|Select|Wrap|Line Numbers
  1. function showTooltip (nextTo, e) {
  2. tip=(!e.target?event.srcElement.value:e.target.value)
and

Expand|Select|Wrap|Line Numbers
  1. ONMOUSEOVER="showTooltip(this,event)"
that removes the errors from IE, but still leaves the variable tip (under IE) undefined

Expand|Select|Wrap|Line Numbers
  1.  <HEAD> 
  2. <STYLE>
  3. #tooltip {
  4. position: absolute;
  5. visibility: hidden;
  6. border: 1px solid black;
  7. background-color: lightyellow;
  8. }
  9. </STYLE>
  10. <SCRIPT>
  11. var descriptions = {
  12. '1': 'This is number 1.',
  13. '2': 'This is number 2.',
  14. '3': 'This is number 3.'
  15. }
  16. function showTooltip (nextTo, e) {
  17. tip=(!e.target?event.srcElement.value:e.target.value)
  18. var tt = document.getElementById('tooltip');
  19. tt.innerHTML = descriptions[tip];
  20. tt.style.left = (getPageLeft(nextTo) + nextTo.offsetWidth) + 'px';
  21. tt.style.top = getPageTop(nextTo) + 'px';
  22. tt.style.visibility = 'visible';
  23. function hideTooltip () {
  24. document.getElementById('tooltip').style.visibilit  y = 'hidden';
  25. function getPageLeft (el) {
  26. var left = 0;
  27. do 
  28. left += el.offsetLeft;
  29. while ((el = el.offsetParent));
  30. return left;
  31. }
  32. function getPageTop (el) {
  33. var top = 0;
  34. do 
  35. top += el.offsetTop;
  36. while ((el = el.offsetParent));
  37. return top;
  38. }
  39. </SCRIPT>
  40. </HEAD>
  41. <BODY>
  42. <DIV ID="tooltip"></DIV>
  43. <SELECT ID="aSelect"
  44. ONMOUSEOVER="showTooltip(this, event)"
  45. ONMOUSEOUT="hideTooltip();"
  46. >
  47. <OPTION VALUE="1">1
  48. <OPTION VALUE="2">2
  49. <OPTION VALUE="3">3
  50. </SELECT>
  51.  
  52. </BODY>
Mar 27 '07 #7
that works... only not for <SELECT MULTIPLE> ... and that is the bit i want to get workin'
Mar 27 '07 #8
acoder
16,027 Expert Mod 8TB
You mean it hides underneath the select?
Mar 28 '07 #9
no, it doesn't fill the tip variable on IE

so i get a tooltip with the text 'undefined'
Mar 28 '07 #10
acoder
16,027 Expert Mod 8TB
See this thread.

It seems that for a multiple select, IE gives the select object. I'm not sure what its value would be. That link might help you.
Mar 28 '07 #11
Thank you for your reply, i did see this post, and under IE it gives the wrong value, the name of the selectbox that is... not the value of the <option> element

and the select alert doesn't work at all
Mar 28 '07 #12

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

Similar topics

12
by: * ProteanThread * | last post by:
but depends upon the clique: ...
3
by: rollasoc | last post by:
Hi, Doing a bit of system testing on a Windows 98 laptop. (.Net 1.1 app). Did a bit of testing. Loaded a previously saved file. A gray box appeared with the text and buttons all white...
23
by: Jeff Rodriguez | last post by:
Here's what I want do: Have a main daemon which starts up several threads in a Boss-Queue structure. From those threads, I want them all to sit and watch a queue. Once an entry goes into the...
7
by: Scott M. | last post by:
How can I disable the cross-site scripting check for one particular page of a site?
8
by: Pieter | last post by:
Hi, I'm having some weird problem using the BackGroundWorker in an Outlook (2003) Add-In, with VB.NET 2005: I'm using the BackGroundWorker to get the info of some mailitems, and after each item...
3
by: jlamanna | last post by:
I was wondering if there was a utility that could tell you when your C# application is making cross-apartment COM calls. I have a fairly large application that makes extensive use of a 3rd party...
1
by: Rob Woodworth | last post by:
Hi, I'm having serious problems getting my report to work. I need to generate a timesheet report which will contain info for one employee between certain dates (one week's worth of dates). I...
6
by: Robert Bravery | last post by:
Hi all, Can some one show me how to achieve a cross product of arrays. So that if I had two arrays (could be any number) with three elements in each (once again could be any number) I would get:...
7
by: Charles | last post by:
I'd like to develop a simple cross-platform application in C++. I'd like it to run in Windows, OS X, PC-BSD and Linux. From my research, it seems I should use Qt or Gtk as a graphical library. Do...
6
by: ampo | last post by:
Hello. Can anyone help with cross-domain problem? I have HTML page from server1 that send xmlHTTPRequest to server2. How can I do it? Thanks.
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.