473,503 Members | 1,635 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cursor position in textarea? (XY pos, not caret index)

Is it possible to determine the caret position, in terms of x/y
pixels, within a textarea? (I want to have a suggestion box pop up
under where you're typing... so i need to determine where you are
typing.)

-Derik

(OTOH, finding the Caret position-- between what characters the cursor
is positioned-- uses the function below. I include it to be nice to
future searchers, and because it took me an hour of frustrated
searching to find.)

function getCaretPos(el) {
if (typeof el.selectionStart != 'undefined')
return el.selectionStart;
else if (document.selection)
return
Math.abs(document.selection.createRange().moveStar t('character',
-1000000));
}
Sep 28 '08 #1
3 8374
ReGenesis0 wrote:
Is it possible to determine the caret position, in terms of x/y
pixels, within a textarea? (I want to have a suggestion box pop up
under where you're typing... so i need to determine where you are
typing.)
I do not think it is generally possible to determine the coordinates
of the caret since you cannot always know which font is used.

I would be confused if the suggestion box would move while I am typing, so
it should suffice to calculate the offset position and height of the control.
PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f8*******************@news.demon.co.uk>
Sep 28 '08 #2
SAM
Le 9/28/08 4:11 PM, ReGenesis0 a écrit :
Is it possible to determine the caret position, in terms of x/y
pixels, within a textarea? (I want to have a suggestion box pop up
under where you're typing... so i need to determine where you are
typing.)

I don't know if ... but :
<http://www.quirksmode.org/js/findpos.html>

--
sm
Sep 28 '08 #3
On Sep 28, 9:59*am, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
ReGenesis0 wrote:
Is it possible to determine the caret position, in terms of x/y
pixels, within a textarea? *(I want to have a suggestion box pop up
under where you're typing... so i need to determine where you are
typing.)

I do not think it is generally possible to determine the coordinates
of the caret since you cannot always know which font is used.
*grumble*
I would be confused if the suggestion box would move while I am typing, so
it should suffice to calculate the offset position and height of the control.
It's a *large* textarea box. Placing the popup at top or bottom would
require scrolling the browser.

Is there a method for determining the rows then? Just hovering the
box below the current line would probably work...

-Derik
Sep 28 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
6805
by: Krzysztof Kujawski | last post by:
Hi Is there posibility to (and how to do this): a) add a string in the current cursor position? b) add string before and after selection in textarea e.g. selection c) if I put with...
2
28862
by: AP | last post by:
I am trying to find the integer value for the cursor position in a text box, in particular I want to find out if I am at the end of some text that I typed or at the beginning. I am using IE 6. ...
2
6775
by: Thomas | last post by:
Hi there, I'd like to insert a text into a textarea at the current cursor position when you click on a button, but I only found out how to insert a text at the end of the textarea. Is it...
7
30310
by: Paul Gorodyansky | last post by:
Hi, Say I have a text in my TEXTAREA box - 01234567890 I want - using script - insert say "abc" in the middle. Works almost OK in Internet Explorer (with one problem) based on their example...
1
1943
by: Ilann | last post by:
Hi, I need to get the text cursor position in a richedit Control, ie I want my ContextMenu to appear exactly where the user is typing text, Thanks
2
6761
by: DaveR | last post by:
Can anybody help me to a)get the user's cursor insertion point (caret) from a multiline textbox, using client-side script I suppose, and then b)return the position to VB code behind? I have...
3
2328
by: Doug Bell | last post by:
Hi, How do I get the position of the cursor (as character position) when it is in a text box with no text selected? Thanks Doug
2
2796
by: gsb58 | last post by:
Hi! I'm new to VB.NET Anybody that could show me how to find the cursor position in a RichEdit? That is: when user click anywhere in the box and there's some text already, I want to...
0
7202
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7280
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7332
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7462
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.