473,581 Members | 2,833 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I get the caret position in a textarea?

I have trawled the internet for a solution to this one . All I need is the
caret position as a number. I have seen quite a few text insertion functions
that do something like this :

textarea.caretP os = document.select ion.createRange ().duplicate()

and then operate on the caretPos object - but all these solutions seem to
work by creating a selected area in the text and then replacing it - I just
want the caret position as a number.

Anyone got any clues?

Thanks

Jul 23 '05 #1
4 5672
Ivo
"torch" <to***@torch.co m> wrote in message
news:ca******** **@newsg4.svr.p ol.co.uk...
I have trawled the internet for a solution to this one . All I need is the
caret position as a number.


See this thread (url may wrap):
<URL:
http://groups.google.com/groups?thre...44a441750%40ne
ws.wanadoo.nl >

HTH
Ivo

Jul 23 '05 #2
On Sun, 13 Jun 2004 17:16:28 +0200, Ivo wrote:
http://groups.google.com/groups?thre...44a441750%40ne
ws.wanadoo.nl


Also, try this alternate..
<http://groups.google.c om/groups?th=296d4 38401e265d5>

(shrugs) I have been practising the 'black art'
of shortening Google Usenet URL's recently and
have become quite good at it. ..Maybe I should
write a page on it.

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
Jul 23 '05 #3
Ivo
"Andrew Thompson" wrote
Ivo wrote:
http://groups.google.com/groups?thre...44a441750%40ne ws.wanadoo.nl


Also, try this alternate..
<http://groups.google.c om/groups?th=296d4 38401e265d5>

(shrugs) I have been practising the 'black art'
of shortening Google Usenet URL's recently and
have become quite good at it. ..Maybe I should
write a page on it.


Yes, please do. This is impressive.
Ivo
Jul 23 '05 #4
torch wrote:
I have trawled the internet for a solution to this one . All I need is the
caret position as a number. I have seen quite a few text insertion functions
that do something like this :

textarea.caretP os = document.select ion.createRange ().duplicate()

and then operate on the caretPos object - but all these solutions seem to
work by creating a selected area in the text and then replacing it - I just
want the caret position as a number.

Anyone got any clues?


In the IE DOM, TextRange objects have a boundingLeft property.
Reads to me as it was what you are looking for:
<http://msdn.microsoft. com/workshop/author/dhtml/reference/methods/duplicate.asp>

In the Gecko DOM, HTMLTextAreaEle ment objects have a selectionStart
property:
<http://www.xulplanet.c om/references/objref/HTMLTextAreaEle ment.html>
HTH

PointedEars
Jul 23 '05 #5

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

Similar topics

5
3981
by: Zbigniew Braniecki | last post by:
Hello. I'm looking for any way to grab caret position in textarea (start, end - if selection) in Internet Explorer. Is it at all possible? Also any idea for doing it in Opera, KHTML would be appreciated :) Greetings Gandalf
7
30321
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 at http://msdn.microsoft.com/library/en-us/dnwebteam/html/webteam12032001.asp in the chapter "O Cursor, Where Art Thou".
1
2385
by: j_macaroni | last post by:
I found this code to calculate the caret position in a textarea. In the script getCaret below, I pass it the TextArea1 element. It seems to work until you press a CR. In which case you get the wrong result because of this line: "textEl.caretPos.move("character",1)==1 ) --i; " So now if you have 3 lines and you are at line 0, column 0 it...
2
6508
by: rjonasz | last post by:
Hey Everyone, I'm trying to scroll a textarea to the position of the caret which is below the visible area of the textarea in firefox. I have code which works in IE but the code I use for firefox creates an elastic band effect. The textarea quickly scrolls down then bounces up to the top, no matter what I try. Has anyone run into the...
7
3072
by: =?ISO-8859-1?Q?=22=C1lvaro_G=2E_Vicario=22?= | last post by:
I need to emulate the missing "maxlegth" attribute in "textarea" fields but all my Google searches either lead to obsolete scripts that overwrite the "value" property (thus losing caret position) or to complex solutions that work on top of specific frameworks. Do you have some reference on how to do it? I'd like to make it work in at least...
3
8395
by: ReGenesis0 | last post by:
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...
0
7876
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8156
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8310
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7910
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8180
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6563
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5681
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
2307
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1144
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.