473,386 Members | 1,779 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 8362
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
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
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
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
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
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
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
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
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.