Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

event.clientX

Status
Not open for further replies.

BKer

Programmer
Apr 17, 2001
62
US
I am trying to get the position of the text/mouse when the user hovers of the text. I have tried to use teh event.clientx, but it aligns the text that I have pop up in the wrong place. I am basically trying to eliminate hard coding the pixel position that I currently use because I want to dynamically generate the pixel number so I don't have to change every number when I add a new one. Any help would be great, thanks.

<Div name=&quot;empCountDiv&quot; id=&quot;empCountDiv&quot; style=&quot;position: absolute; visibility: hidden; background: white; color: black; font-size: 15px&quot;>
Listing of all employees by department and by employee type (Full time, students, and temps).
</Div>
<Font onmouseover=&quot;empCount(true);&quot; onmouseout=&quot;empCount(false);&quot;>&nbsp&nbsp&nbsp&nbsp&nbsp<a href=empcount.asp>Employee Count</a></Font><BR>
<Script>
function empCount(a) {
if (a) {

empCountDiv.style.top = 278;
empCountDiv.style.left = 270;
empCountDiv.style.width = 500;
empCountDiv.style.visibility = &quot;visible&quot;;
}
else
empCountDiv.style.visibility = &quot;hidden&quot;;
//**************************************
}
</Script>
 
There is event.x and event.y and also there is event.screenX and event.screenY in IE. Maybe those might work better since getting the x and y within a client will most likely offset where a popup should come up, use absolute positions for popups.
 
I have tried those as well, but the same thing happens and pops up in the same place. Do you know if you can grab the actual pixel position of <a href> link, basically just where it is located on the page. Thanks again
 
Everything matters on the browser your using......

Here is the code that works in IE5+, for netscape the event procedures are located in a different place in the heirarchy so you have to look up where to call it, but this code works perfectly in IE.

<script>
function empCount(a) {
if (a) {

empCountDiv.style.top = event.y;
empCountDiv.style.left = event.x + 25; //added 25 pixels since otherwise the popup is right over our text
empCountDiv.style.width = 500;
empCountDiv.style.visibility = &quot;visible&quot;;
}
else
empCountDiv.style.visibility = &quot;hidden&quot;;
//**************************************
}
</script>

<Div id=&quot;empCountDiv&quot; style=&quot;position: absolute; visibility: hidden; background-color: white; color: black; font-size: 15px&quot;>
Listing of all employees by department and by employee type (Full time,
students, and temps).</div>
<Font onmouseover=&quot;empCount(true);&quot; onmouseout=&quot;empCount(false);&quot;>
<a href=empcount.asp>Employee Count</a></Font>
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top