• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Positioning the cursor in an input field

 
Ranch Hand
Posts: 282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Let's get him boys! We'll make him read this tiny ad!
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic