This week's book giveaway is in the iOS forum.
We're giving away four copies of Classic Computer Science Problems in Swift and have David Kopec on-line!
See this thread for details.
Win a copy of Classic Computer Science Problems in Swift this week in the iOS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Positioning the cursor in an input field  RSS feed

 
Ranch Hand
Posts: 282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way to obtain the position of the cursor in an input field? Conversely, is there a way precisely position the cursor in an input field?

I am writing a mask function for an input field and it occurred to me that the user may want to use the arrow keys to go back and insert a missing character in the input field.

It is easy enough to trap arrow keys and allow the user to insert a new character but when he does and the input field value is reformatted, the cursor goes to the end of the field, i.e. after the last character.

What I would like to do is put the cursor back to its previous position so that the user may enter multiple characters at the insert point.

Any suggestions would be appreciated.
 
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can not control the position of the cursor in a text field
 
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In IE, there is a TextRange object, that you can use. Not sure, if there something like tatn in Gecko.
See if those links will help:

JavaScript FAQ - store cursor position

look for answer #5 here

carret(cursor) postition in a textarea as an integer
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!