?
Solved

code error...a simple javascript problem...urgent**

Posted on 2004-08-30
9
Medium Priority
?
352 Views
Last Modified: 2010-04-06
Hi,
This code works great for tooltip. but the only problem is...if the strHTM is not defined in the tooltip then it says undefined in the tooltip... how to avoid that? for example...if my code says <a href="#" onMouseover="tooltip(welcome);">welcome</a> then it works gr8...if i am saying <a href="#" onMouseover="tooltip();">welcome</a> then it says undefined...i need a logic to validate that....urgent please.


<html>
<head>
<script>
var oPopup = window.createPopup();
function tooltip(strHTML, oNavigate)
{      
      oPopup.hide();
      oPopup.document.navigateTo = oNavigate;
      oPopup.document.desiredX = event.screenX+12;
      oPopup.document.desiredY = event.screenY+12;    
      if(strHTML!=""){
            oPopup.document.body.innerHTML = '<table style=\'background:#ffffcc; border:1px solid black; padding:4px; font-family:tahoma; font-size:10px; width:100%;filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0,StartColorStr=white, EndColorStr=yellowgreen)\' ><tr><td><table style=\'background:#ffffcc; border:1px solid yellowgreen; padding:4px; font-family:tahoma; font-size:10px; width:100%;filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0,StartColorStr=yellowgreen, EndColorStr=white)\' ><tr><td>' + strHTML + '</td></tr></table></td></tr></table>';
      }
      oPopup.document.timerID = setTimeout("showtooltip()", 500);
}
function showtooltip()
{
      // This popup is temporary and is used only to detect what height the popup should be displayed. This is important because the
      // popup size will vary between definition text lengths.
      var popupBody = oPopup.document.body;
      oPopup.show(0,0,0,0);
      var realHeight = popupBody.scrollHeight;
      var realWidth = popupBody.scrollWidth;
      //hide the dimension detector popup.
      oPopup.hide();
      //Show the actual popup with correct width and height.
      oPopup.show(oPopup.document.desiredX, oPopup.document.desiredY,realWidth, realHeight);      
}
function hidetooltip()
{
      oPopup.hide();
      // cancel delayed display of tooltip
      if (oPopup.document.timerID)
      {
            clearTimeout(oPopup.document.timerID);
            oPopup.document.timerID = 0;
      }
}
</script>
</head>
<BODY>
<a href="#" onMouseOver="tooltip()">Welcome</a>
</body>
</html>
0
Comment
Question by:SubhaBabu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 13

Expert Comment

by:StormyWaters
ID: 11933637
Change:
 if(strHTML!=""){
to:
 if(strHTML!=null){

and it won't show a tooltip at all if no text is specified.
You could also make it show some default text by changing the tooltip() function to:

function tooltip(strHTML, oNavigate)
{    
     oPopup.hide();
     oPopup.document.navigateTo = oNavigate;
     oPopup.document.desiredX = event.screenX+12;
     oPopup.document.desiredY = event.screenY+12;    
     if(strHTML==null) {
       strHTML = "Your default message";
     }
          oPopup.document.body.innerHTML = '<table style=\'background:#ffffcc; border:1px solid black; padding:4px; font-family:tahoma; font-size:10px; width:100%;filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0,StartColorStr=white, EndColorStr=yellowgreen)\' ><tr><td><table style=\'background:#ffffcc; border:1px solid yellowgreen; padding:4px; font-family:tahoma; font-size:10px; width:100%;filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0,StartColorStr=yellowgreen, EndColorStr=white)\' ><tr><td>' + strHTML + '</td></tr></table></td></tr></table>';
     oPopup.document.timerID = setTimeout("showtooltip()", 500);
}


0
 
LVL 2

Author Comment

by:SubhaBabu
ID: 11933846
Thanks for your immediate reply....your solution works...if it has only one link ....if i add like

<a href="#" onMouseOver="tooltip()">Welcome</a> <a href="#" onMouseOver="tooltip('you there')">Welcome</a>

this...it shows "you there" for both the links
0
 
LVL 2

Author Comment

by:SubhaBabu
ID: 11933857
And i do not want to give a default message, since i am gonna use this in too many places...
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 13

Expert Comment

by:StormyWaters
ID: 11933883
That doesn't happen for me. IE, obviously, because this doesn't work anywhere else. Version 6.0. What version are you looking at?
0
 
LVL 2

Author Comment

by:SubhaBabu
ID: 11933903
i want it to work only in IE 6....
0
 
LVL 13

Expert Comment

by:StormyWaters
ID: 11933915
Oh, wait, yes it does. Will look.
0
 
LVL 13

Accepted Solution

by:
StormyWaters earned 1000 total points
ID: 11934048
function tooltip(strHTML, oNavigate)
{    
     oPopup.hide();
       oPopup.document.body.innerHTML = '';
     oPopup.document.navigateTo = oNavigate;
     oPopup.document.desiredX = event.screenX+12;
     oPopup.document.desiredY = event.screenY+12;    
     if(strHTML!=null){
          oPopup.document.body.innerHTML = '<table style=\'background:#ffffcc; border:1px solid black; padding:4px; font-family:tahoma; font-size:10px; width:100%;filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0,StartColorStr=white, EndColorStr=yellowgreen)\' ><tr><td><table style=\'background:#ffffcc; border:1px solid yellowgreen; padding:4px; font-family:tahoma; font-size:10px; width:100%;filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0,StartColorStr=yellowgreen, EndColorStr=white)\' ><tr><td>' + strHTML + '</td></tr></table></td></tr></table>';
       }
      
     oPopup.document.timerID = setTimeout("showtooltip()", 500);
}
0
 
LVL 2

Author Comment

by:SubhaBabu
ID: 11934426
Hi there...

Its still has the problem....
0
 
LVL 13

Expert Comment

by:StormyWaters
ID: 11934459
Okay... I have no idea then. Because it works fine for me.
0

Featured Post

Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
There are two main kinds of selectors in CSS: One is base selector like h1, h2, body, table or any existing HTML tags.  For instance, the following rule sets all paragraphs (<p> elements) to red: (CODE) CSS also allows us to define our own custom …
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question