Wrox Programmer Forums
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 25th, 2006, 07:06 AM
Authorized User
 
Join Date: Feb 2006
Posts: 63
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via Yahoo to Hannibal
Default creating tooltips?

How to create a dynamic tooltip in java script?
ie., according to the user selection, the tool tip should show the selected thing? can anyone please help..
 
Old April 25th, 2006, 09:05 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

heres a working tooltip;

Code:
/***********************************************
* Cool DHTML tooltip script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var offsetxpoint=-60 //Customize x offset of tooltip
var offsetypoint=20 //Customize y offset of tooltip
var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)
var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(thetext, thecolor, thewidth)
{
if (ns6||ie){
if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
tipobj.innerHTML=thetext
enabletip=true
return false
}
}

function positiontip(e){
if (enabletip){
var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
//Find out how close the mouse is to the corner of the window
var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20
var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20

var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<tipobj.offsetWidth)
//move the horizontal position of the menu to the left by it's width
tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px"
else if (curX<leftedge)
tipobj.style.left="5px"
else
//position the horizontal position of the menu where the mouse is positioned
tipobj.style.left=curX+offsetxpoint+"px"

//same concept with the vertical position
if (bottomedge<tipobj.offsetHeight)
tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px"
else
tipobj.style.top=curY+offsetypoint+"px"
tipobj.style.visibility="visible"
}
}

function hideddrivetip(){
if (ns6||ie){
enabletip=false
tipobj.style.visibility="hidden"
tipobj.style.left="-1000px"
tipobj.style.backgroundColor=''
tipobj.style.width=''
}
}

document.onmousemove=positiontip

www.crmpicco.co.uk
www.ie7.com
 
Old April 25th, 2006, 09:06 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

the required CSS:
Code:
#dhtmltooltip{
position: absolute;
width: 150px;
border: 1px solid black;
padding: 2px;
background-color: blue;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size:9px;
visibility: hidden;
z-index: 100;
/*Remove below line to remove shadow. Below line should always appear last within this CSS*/
filter: progid:DXImageTransform.Microsoft.Shadow(color=gray,direction=135);
}

www.crmpicco.co.uk
www.ie7.com
 
Old April 26th, 2006, 01:23 AM
Authorized User
 
Join Date: Feb 2006
Posts: 63
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via Yahoo to Hannibal
Default

Thank you for providing the code. I have a doubt, hope you would be kind enough to help me.
I am providing the tooltip in a calendar,which i have written in jsp. This calendar helps the user to select a date and input some description about the date and store in database(MySQL is my database). Once the description in entered and stored in database, i want to show the description as the tooltip.

Is it possible to use the code you have given above for my scenario.

Thanks in Advance

 
Old April 26th, 2006, 05:25 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

you could hold the description in a HTML hidden form field and that way your JavaScript could access it:

Code:
<input type="hidden" name="desc" />
and in your javascript pass
Code:
document.form.desc.value
to your tooltip function?

www.crmpicco.co.uk
www.ie7.com
 
Old April 26th, 2006, 05:48 AM
Authorized User
 
Join Date: Feb 2006
Posts: 63
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via Yahoo to Hannibal
Default

can i use the tooltip function that u have given?
Sir, You had provided a code. should it saved as .dhtml file. i had created a hidden texctfield for the description event as you had mentioned.
Code:
<div id="descr" style="visibility:hidden">Enter Description  : <input type="text" name="descText" value=""> </div>
where should i write the mouseover event?
 
Old April 27th, 2006, 09:20 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

yesm you can use the function i provided.

save it as a .js (javascript) file.

you also need:

Code:
<style type="text/css">
#dhtmltooltip{
position: absolute;
width: 150px;
border: 1px solid black;
padding: 2px;
background-color: blue;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size:9px;
visibility: hidden;
z-index: 100;
/*Remove below line to remove shadow. Below line should always appear last within this CSS*/
filter: progid:DXImageTransform.Microsoft.Shadow(color=gray,direction=135);
}
</style>
then when you want to SHOW the div TEST

www.crmpicco.co.uk
www.ie7.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to hide tooltips in Crystal Reports? NinaWilliam ASP.NET 1.0 and 1.1 Basics 1 July 13th, 2008 11:48 PM
Tooltips in a datagrid Ric_H .NET Framework 1.x 0 November 9th, 2006 07:46 PM
DHTML Tooltips in Preview Page deepak.vasudevan Forum and Wrox.com Feedback 0 September 2nd, 2005 03:01 AM
Useless Tooltips showing on Report ejan Crystal Reports 0 February 4th, 2005 03:42 PM
tooltips showing on crystal reports viewer ejan Pro VB 6 0 December 21st, 2004 02:47 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.