Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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

![]() |
![]() |
![]() |

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