Solved

Cursor Position in Textarea

Posted on 2000-03-24
7
1,499 Views
Last Modified: 2012-06-27
How can I capture the cursor position in a textarea form field?
0
Comment
Question by:bfredett
7 Comments
 
LVL 1

Expert Comment

by:technoman
ID: 2655652
what do you mean?
0
 
LVL 3

Expert Comment

by:MHQ
ID: 2655658
If i'm correct, you want to get the exact x and y coordinates of the cursor. Not for the page but for the textarea, right?
0
 
LVL 2

Expert Comment

by:HolySpirit
ID: 2655995
bfredett,
I think u want to capture the position of CARET (the flashing vertical bar) of the text area ...
-- Holy Spirit
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 10

Expert Comment

by:kollegov
ID: 2656197
At least "java-script:"
will cause errors.
Use "javascript:" instead.

Also URL where we can check all in action will be quite helpfull...
0
 
LVL 10

Expert Comment

by:kollegov
ID: 2656207
Oppsss, I posted comment in wrong thread, sorry, messed up windows...

Do you need to find cursor offset in chars from text begining inside textarea ?
This is absolutely impossible for NN4
and after spending 15 minutes in MSDN library and didn't find anything for MIE I almost sure this is also impossible for MIE too...

What can be done is replacng textarea with JavaApplet with java.lang.TextArea
inside and using this applet instead of HTML TextArea element, but this will be a lot of headaches
1. Creating applet
2. Providing methods to get/set in Applet and get Position
3. Communicating with Applet from JavaScript (Syncronization problems, as applets loads slow, than you need to be sure it loaded, before trying to access aplet methods..)
4. On submit you would need to get data from applet and copy into hidden field in form..

This can be done, but not easy..

Virtual_Max (kollegov)



0
 
LVL 8

Accepted Solution

by:
xabi earned 200 total points
ID: 2656813
Try this trick, Is the only thing you can do. I wrote this script for other question.

----------- 8< --------- 8< -------
<html>
<head>
<title>Example</title>
<script language="javascript">
<!--
var sValue = "" 
function testit(idForm) {
 sTmp = idForm.txtmsg.value
 iXPos = 1
 iYPos = 1
 iTmp  = 0
 bIn = true
 while (iTmp<sTmp.length) {
  cChar1 = sTmp.charAt(iTmp)
  cChar2 = sValue.charAt(iTmp)
  iXPos++
  if (cChar1 == "\r") {
   iXPos = 1
   iYPos++
  }
  if (cChar1 != cChar2) break
  iTmp++
 }
 idForm.valuex.value = iXPos
 idForm.valuey.value = iYPos
 sValue = sTmp
}
//-->
</script>
</head>
<body background="bgcolor.gif" vlink="orange" alink="Lime" onload="testit(document.myform)">
<form name="myform">
 <textarea name="txtmsg" rows="4" cols="27" wrap="off" onKeyUp="testit(this.form)"></textarea>
 <br>
 X: <input type="text" name="valuex" readonly>
 <br>
 Y: <input type="text" name="valuey" readonly>
</form>
</body>
</html>
----------- 8< --------- 8< --------

xabi
0
 

Author Comment

by:bfredett
ID: 2656905
Thanks xabi!

I found your script after posting the question.  Works great.  Now, I'd like to capture the arrow keys and update the x and y textboxes as well.  Any way to do this?

Thanks,
Brian
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Close "X" button on window popup in Firefox 7 34
Don't understand jquery promises 6 36
window.setInterval not firing 7 29
regx  exclude  pattern 6 26
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now