473,396 Members | 1,898 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,396 software developers and data experts.

Set caret position

cc
Hi,
Is possible set and get the caret position of cursor in a text field ?

Thanks,
Carlo
Jul 23 '05 #1
4 9323


cc wrote:
Is possible set and get the caret position of cursor in a text field ?


In some browsers you can do that, see
<http://www.faqts.com/knowledge_base/view.phtml/aid/13562/fid/130>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
cc
> In some browsers you can do that, see
<http://www.faqts.com/knowledge_base/view.phtml/aid/13562/fid/130>


Thanks,
but how can get caret position?

Carlo
Jul 23 '05 #3


cc wrote:
In some browsers you can do that, see
<http://www.faqts.com/knowledge_base/view.phtml/aid/13562/fid/130>
but how can get caret position?


For Mozilla you can read out
textControl.selectionStart
textControl.selectionEnd
as number offsets, if both are the same then you have the caret position
as a number. If they are not the same I am not sure what you would
regard as the caret position, probably selectionStart.
IE doesn't expose the caret position as a number, you can insert stuff
at the caret position with the methods described.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #4
Martin Honnen wrote:
cc wrote:
In some browsers you can do that, see
<http://www.faqts.com/knowledge_base/view.phtml/aid/13562/fid/130>

but how can get caret position?


For Mozilla you can read out
textControl.selectionStart
textControl.selectionEnd
as number offsets, if both are the same then you have the caret position
as a number. If they are not the same I am not sure what you would
regard as the caret position, probably selectionStart.


In some apps that's true (e.g. Consider Excel where you can select
(possibly non contiguous) ranges and then cycle through the cells of
this range with the tab key), but near as I can tell, the notion of caret
position (also in Word or OE) is either not well defined here (ie has no
meaning when characters are selected) or means the entire selected area.

In particular, note that the caret does not blink when you have characters
selected. Also, if you have characters selected and use the right arrow
key, the currently selected range will "collapse" and you will wind up
to the right of that formerly selected range. Similarly, pressing the
left arrow key will collapse the range and put the caret to the left (at
least in IE 6, FF 1.0.1+). I haven't been able to think up any experiment
(eg. cut, paste, etc.) which would reveal a differentiation between a left
or right internal caret position.

My testing has been minimal though, and I am happy to be corrected on this point.

Csaba Gabor from Vienna
Jul 23 '05 #5

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

Similar topics

2
by: - ions | last post by:
hi, i am in the procces of writing a chat program for a main Assigment, the problem im stuck on is one of the Carets position in a JTextArea, when i hit the enter key, it appends the msg to the...
1
by: Barry | last post by:
Retoring Caret Position after text field correction -------------------------------------------------------------------------------- Hi, my code has the following form - function...
4
by: torch | last post by:
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 : ...
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: ryanmhuc | last post by:
Is there a way to get the caret position of a text input using FireFox. I am aware of ways to such with IE but have been unable to accomplish in FireFox and have not found a solution in the groups...
6
by: kurotsuke | last post by:
Hi, I need to know the position (X, Y cohordinates) of the caret. I'm using the function: private static extern int GetCaretPos(ref POINT lpPoint); I'm actually getting a result but I...
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...
0
by: Oenone | last post by:
I would like to set the caret position in a (single-line) textbox to a position based on the number of pixels from the left of the control. For example, I want the caret to be positioned 50...
0
Jezternz
by: Jezternz | last post by:
Okay, so a while back I managed to retrieve it correctly. In this thread: http://bytes.com/topic/javascript/answers/786211-retrieving-caret-start-end-values#post3127765 However I have found...
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: 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...
0
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
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...
0
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...

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.