Arrays on mouseover displayed in tooltip?

M

marcbinaus

Hi,

I have 3 textboxes A B C
The user can only enter single digit numbers in the textboxes, and if
they hover over a blank textbox it would give them the options through
a tooltip of what numbers are left over.
For instance if A =1, tooltip over B & C would = "2,3,4,5,6,7,8,9"
and B = 4, tooltip over C= "2,3,5,6,7,8,9"

I worked out a solution in vb, but that needs page postbacks, and I
would like to move away from that and make it smoother

So, how do I:
Write an array in javascript and calculate what is misssing if the
mouse hovers over a blank textbox and transfer whats missing to a
tooltip?


I suppose it would share the same logic of a sodoku puzzle thinking
about it, but sadly its not as exciting as that.
 
R

Randy Webb

(e-mail address removed) said the following on 11/3/2005 6:28 AM:
Hi,

I have 3 textboxes A B C
The user can only enter single digit numbers in the textboxes, and if
they hover over a blank textbox it would give them the options through
a tooltip of what numbers are left over.

hover over the textbox? Use the onFocus to make it show, the onBlur to
make it go away.
For instance if A =1, tooltip over B & C would = "2,3,4,5,6,7,8,9"
and B = 4, tooltip over C= "2,3,5,6,7,8,9"

onFocus="showTooltip(this)"

function showTooltip(elem){
var a = elem.form.elements['textbox1'].value;
var b = elem.form.elements['textbox2'].value;
var c = elem.form.elements['textbox3'].value;
var masterString = "0123456789";
var notUsed = masterString.replace(a,'').replace(b,'').replace(c,'');
var notUsedArray = notUsed.split()
alert(notUsedArray)
//use the reference to elem to know where/which tooltip to display
//the results of notUsed
}
I worked out a solution in vb, but that needs page postbacks, and I
would like to move away from that and make it smoother
So, how do I:
Write an array in javascript and calculate what is misssing if the
mouse hovers over a blank textbox and transfer whats missing to a
tooltip?

Use a simple string, replace what is used so far with blank space, then
split it to get an Array.
I suppose it would share the same logic of a sodoku puzzle thinking
about it, but sadly its not as exciting as that.

What is a sodoku puzzle?
 
M

marcbinaus

Thanks for the answer, I have used your code and the following code:
<script type="text/javascript">

/***********************************************
* 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

</script>

and written this in the pageload
C.Attributes.Add("onMouseover", "ddrivetip(showTooltip(C,'yellow',
300)")

and it works great apart from I can't transfer the notUsedArray to
appear in the textbody.
Can you help?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top