Hi everybody,
I need to calculate caret coordinates within TEXTAREA in pixels.
Pointing me to the right direction will be appreciated.
Thanks
MaxIRMX
11 7326
the task is to find CARET coordinates within textarea.
This is a reach, but you might try catching the onChange event from the textarea element in question, and checking the coordinates from the event. I am not sure if it would return the location of the carrot, or the mouse cursor.
If it does return the position of the carrot it would probably be the position on the page not the position inside the textarea. You could get the position in the text area though by subtracting the X, Y values from the position of the TextArea elment. The different should be the position inside the textarea.
Sorry, it does not. I understand how to calculate object coordinates. However, the task is to find CARET coordinates within textarea. It looks like creating a range might work for IE but I could not find anything that worked for Firefox.
Can you post the code that seems to work in IE.
Firefox has a different model to IE for working with ranges/selections.
Can you post the code that seems to work in IE.
Firefox has a different model to IE for working with ranges/selections.
-
-
refT.caretPos = document.selection.createRange();
-
// refT is the TextArea object
-
...
-
// irrelevant stuff
-
...
-
posT=findPos(refT.caretPos);
-
posT[0]+=document.documentElement.scrollLeft;
-
posT[1]+=document.documentElement.scrollTop;
-
...
-
// posT now holds caret position within document
-
...
-
function findPos(obj)
-
{
-
var curleft = curtop = 0;
-
if (obj)
-
{
-
do
-
{
-
curleft += obj.offsetLeft;
-
curtop += obj.offsetTop;
-
} while (obj = obj.offsetParent);
-
}
-
return [curleft,curtop];
-
}
-
Non-IE browsers use the W3C Range/Mozilla Selection.
... and W3C Range/Mozilla Selection object attributes provide offset in characters relative to the selected node.
Thank's everybody. This one works for Firefox. It does not work for IE but I can manage it.
Good to hear that you've something that works, though not sure why it wouldn't work in IE. However, since you have something working for IE, a little bit of feature detection [if (document.selection) ...] will do the trick.
According to the quirksmode link, the standard 'range' doesn't work in IE but does work in all the modern browsers.
Yes, of course (as I mentioned earlier).
I would've thought that the linked code would have worked in IE too.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Atif |
last post by:
Hello all,
In my html page I want to add an image say of 800x600. Now I want that
when ever I am given two coordinates on this image say (x1, y1)=(50,
100) and (x2, y2)=(200, 300), the java script...
|
by: Noah |
last post by:
I have a text field in a form. I want the user to be able to click
a DELETE button and have the character at the cursor position deleted.
This would be just as if the user had pressed the Back...
|
by: phil cunningham |
last post by:
I am new to C# and GDI+ so I may have missed a simple way of doing this.
I am trying to use the mouse to pick object up by seeing if the mouse position is Inside the object.
However, I am using...
|
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...
|
by: Ben R. |
last post by:
Hi there,
I'm designing a winforms app in VB.NET 2.0 and have a textbox control and
also some toolbar buttons. I want to have it such that when the user clicks a
toolbar button, some predefined...
|
by: Bob Bedford |
last post by:
Hello,
I've some geographical coordinates and I'd like to put them on a map.
Example: I've the map of the USA. Once I've selected Chicago, I'd like a
point-cross or what ever, on the Chicago...
|
by: jackiepatti |
last post by:
QUESTION:
I have a web page containing a form that contains an image instead of a
submit button, e.g.
<form name='myform' action='get' method='otherpage.asp'>
<input type='image'...
|
by: =?Utf-8?B?QWxleCBLLg==?= |
last post by:
Hi all
How do I get current coordinates (X,Y) of the caret symbol in a multi-line
text box?
Thank you
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
| |