From:  jekillen <>
Date:  24 Apr 2008 13:25:22 Hong Kong Time

cursor position in text field?


Is there a method in javascript for detecting the string position of 
the cursor when
it is set in a text field or textarea element of a form?
I have been testing key codes for keypress events and the arrow keys do 
seem to generate unique codes for up, down,left.right. The delete key 
8 for the code. But if I set the cursor in a text field and arrow to 
the right and delete
a character and type in a new one, I want to be able to track how a 
string has been
changed and update an internal string variable as the changes are made.

This variable receives character input as I type. If I arrow back and 
delete and
replace a character or two, these characters will be added to the end 
of the string
and I want the corresponding characters in the string to be changed. So 
I want
to be able to detect the cursor position in the string when the 
correction is made.

I am using a Mac for development, and specifically, a Mac laptop. I am 
that as far as browser software is concerned, Each platform specific 
version will
use a common key code set, I presume.

And references, suggestions, etc?
Thanks in advance.
Jeff K