Computing.Net > Forums > Programming > Javascript cursor in text field

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Javascript cursor in text field

Reply to Message Icon

Name: vinhwsu
Date: August 3, 2004 at 19:22:03 Pacific
OS: 2000
CPU/Ram: 1g
Comment:

Hello all,

Can someone help me with the following problem?

I have a text field for date input. The text field already had --/--/---- in there.

When user input 1, it should have something like 1-/--/---- . and the cursor should be next to 1.

I used functions onkeyup/onkeydown and window.event.keycode to get the key from keyboard.


var string = '--/--/----'
var key = window.event.keyCode
var num = key - 48 //convert to number 0-9
var index = string.indexOf('-')
var curValue = getElementIdBy"txtDate"].value
getElementIdBy["txtDate"].value= curValue.substring(0,index+1) + num + string.indexOf(10,index+1)

The problem is that the cursor moved to the end of the string.

I tried to set

window.event.keyCode = 37 in the loop to move the arrow to the left. But it just moved only one time. Because the flags did not change.

I have thought of toggling insert/overwritten key. by set window.event.keyCode=45, But it did not work.


Thanks for any suggestion or comments



Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Javascript cursor in text field

Cursors in VB www.computing.net/answers/programming/cursors-in-vb/5976.html

round() in access fields www.computing.net/answers/programming/round-in-access-fields/7879.html

Cursor in VB.NET www.computing.net/answers/programming/cursor-in-vbnet/6832.html