tonelm54
asked on
Where is the cursor in a textbox
I know its possible to find out where the cursor is in a textbox however what Im looking to do is find the actual position of the cursor, so I can put a CSS div just below it, so I can put suggestions in for an intelisence feel.
My first idea was to calculate the text before, and add up each character spacing, and work out where lines would terminate etc, so I can work out the x&y position of the element, but surely there is an easier way of finding this out.
My other issue with my idea, is I have no idea where the scroll bar would be located, nor a way of detecting the scroll value, so it wouldn't work.
Any suggestions?
Thank you
My first idea was to calculate the text before, and add up each character spacing, and work out where lines would terminate etc, so I can work out the x&y position of the element, but surely there is an easier way of finding this out.
My other issue with my idea, is I have no idea where the scroll bar would be located, nor a way of detecting the scroll value, so it wouldn't work.
Any suggestions?
Thank you
Okay the link shows you how to get the cursor position. For the rest of it:
Position of the scrollbar:
window.pageXOffset, window.pageYOffset
IE equivalents are "document.body.scrollLeft" and "document.body.scrollTop"
position of the element:
document.getElementById('i d').offset Top
document.getElementById('i d').offset Left
You just have to do the math to see where you are within the element
Position of the scrollbar:
window.pageXOffset, window.pageYOffset
IE equivalents are "document.body.scrollLeft"
position of the element:
document.getElementById('i
document.getElementById('i
You just have to do the math to see where you are within the element
ASKER
Amick -> Problem with that is it shows where the mouse is, but not where the cursor is.
COBOLdinosaur -> Which shows where the page is scrolled, but not the textbox :-(
The idea is that if Im writing in this comment box I can tell the x and y position if the | (text cursor), and then display a div underneath it.
COBOLdinosaur -> Which shows where the page is scrolled, but not the textbox :-(
The idea is that if Im writing in this comment box I can tell the x and y position if the | (text cursor), and then display a div underneath it.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://dev-notes.com/code.php?q=33