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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I get the location of keypress

Status
Not open for further replies.

inbaron

Programmer
Dec 9, 2002
22
0
0
US
I am trying to create a tooltip that shows the number of characters already typed as I progressively type text in a textarea. I want the tooltip (a div eleemnt) to follow the place where I type the character. I trap the onkeypress event and try to get its location to place the div element there. However, when I event.clientX and event.clientY give the location of the mouse cursor and not where I type. I know I trap get correct event because the event.keyCode always gives me the code of the character I just typed.

Any suggestions?

Thanks

Shai Inbar
 
Maybe you can use the claret position + (fixed width) font size + element positioning to get coordinates?

MSIE might be able to select characters, create a textrange and return the position of the text node but that's a long shot :(

I have definately never tried anything like this before.

----------
I'm willing to trade custom scripts for... [see profile]
 
Thanks

Unfortunately I do not have this flexibility. It has to be both IE and NS compatible and use any font.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top