SubhaBabu
asked on
code error...a simple javascript problem...urgent**
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(welco me);">welc ome</a> then it works gr8...if i am saying <a href="#" onMouseover="tooltip();">w elcome</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.inner HTML = '<table style=\'background:#ffffcc ; border:1px solid black; padding:4px; font-family:tahoma; font-size:10px; width:100%;filter:progid:D XImageTran sform.Micr osoft.Grad ient(Gradi entType=0, StartColor Str=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:D XImageTran sform.Micr osoft.Grad ient(Gradi entType=0, StartColor Str=yellow green, 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.documen t.desiredX , oPopup.document.desiredY,r ealWidth, realHeight);
}
function hidetooltip()
{
oPopup.hide();
// cancel delayed display of tooltip
if (oPopup.document.timerID)
{
clearTimeout(oPopup.docume nt.timerID );
oPopup.document.timerID = 0;
}
}
</script>
</head>
<BODY>
<a href="#" onMouseOver="tooltip()">We lcome</a>
</body>
</html>
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(welco
<html>
<head>
<script>
var oPopup = window.createPopup();
function tooltip(strHTML, oNavigate)
{
oPopup.hide();
oPopup.document.navigateTo
oPopup.document.desiredX = event.screenX+12;
oPopup.document.desiredY = event.screenY+12;
if(strHTML!=""){
oPopup.document.body.inner
}
oPopup.document.timerID = setTimeout("showtooltip()"
}
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.documen
}
function hidetooltip()
{
oPopup.hide();
// cancel delayed display of tooltip
if (oPopup.document.timerID)
{
clearTimeout(oPopup.docume
oPopup.document.timerID = 0;
}
}
</script>
</head>
<BODY>
<a href="#" onMouseOver="tooltip()">We
</body>
</html>
ASKER
Thanks for your immediate reply....your solution works...if it has only one link ....if i add like
<a href="#" onMouseOver="tooltip()">We lcome</a> <a href="#" onMouseOver="tooltip('you there')">Welcome</a>
this...it shows "you there" for both the links
<a href="#" onMouseOver="tooltip()">We
this...it shows "you there" for both the links
ASKER
And i do not want to give a default message, since i am gonna use this in too many places...
That doesn't happen for me. IE, obviously, because this doesn't work anywhere else. Version 6.0. What version are you looking at?
ASKER
i want it to work only in IE 6....
Oh, wait, yes it does. Will look.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi there...
Its still has the problem....
Its still has the problem....
Okay... I have no idea then. Because it works fine for me.
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
oPopup.document.desiredX = event.screenX+12;
oPopup.document.desiredY = event.screenY+12;
if(strHTML==null) {
strHTML = "Your default message";
}
oPopup.document.body.inner
oPopup.document.timerID = setTimeout("showtooltip()"
}