Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to keep track the cursor position in a text field?

Status
Not open for further replies.

evaichow

Programmer
Nov 3, 2000
2
US
I have a text field named "startDate". As the user enters a date in the text field, it will convert all lower case charaters to upper case. The source code is attached below. The user can't make changes in the text field because of 2 problems. First, the user can't use the arrow keys to move the cursor to the position they want because I used the onkeyup event. As the user presses the arrow key once, the cursor will go back to the last position of the input. Second, I can use the mouse to move the cursor to the position I want. However, as I use the Backspace key to erase the character I want to change, the cursor will go back to the last position of the input. My questions are: 1) How to keep track the cursor positon in a text field? 2) How to set the cursor position?

Thank you for your help.

Eva

<font face=&quot;arial&quot; color=&quot;FFFFFF&quot;><small><b>Travel Start Date: </b></small></font><br>

<input name=&quot;startDate&quot; onkeyup=&quot;startDate.value=startDate.value.toUpperCase();&quot; value=&quot;&quot; size=&quot;20&quot;>
 
best idea is to do this afterward... like onblur=&quot;startDate.value=startDate.value.toUpperCase();&quot; adam@aauser.com
 
luciddream is correct. performing the toUpperCase() function whenever the user does key up can make the page lag, especially on slower machines. also, it makes the script repeat less times.

theEclipse
eclipse_web@hotmail.com
robacarp.webjump.com
**-Trying to build a documentation of a Javascript DOM, crossbrowser, of course. E-mail me if you know of any little known events and/or methods, etc.
 
just to avoid confusion my answer was in reference to the following:

Questions:
1) How to keep track the cursor positon in a text field? 2) How to set the cursor position?

Answer:
you can't. jared@aauser.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top