I have 3 text boxes. Month, Day, Year. The text boxes are limited to two integers. After the user enters 01 for the first text box how can I have the cursor advance to the next text box so the user doesn't have to use tab or click in it?
Thanks1
Are you sure about this? I've copied the code and tried it in IE5 & NN7. Doesn't work on either one. I saw a script like this way back when and as I recall, you had to put the input fields in a loop of some sort. I really don't remember but it seemed fairly bulky so I ddn't pay muchy attention to it.
Would like to see this work because I could make good use of it!
Thanks tviman for comments. I didn't try my code yesterday.
(Also I'd appreciate any details rather that just telling "it doesn't work"
Here's what we got: when you pass an object name in function argument, it's considered to be a string, but not an object anymore - and you get a message that focus() method is not applicable to it.
The change is very simple:
function moveFocus(current)
{
if (current.value.length >= 1) //fix here - you could type 3 chars before
document.form1.two.focus(); //fix here - next field name is hardcoded
}
Not so beautiful as before - you need a new function for every form field that automatic focus switch needed, because "next" field name is hard-coded into the function body.
I like the first idea more (just one function for all cases), but this seems to be the most simple solution of the problem.
Of course, in other case if there are many fields that need this action, I'd recommend to think about other solution.
Sorry for the lack of more info, I know better!!! Anyway, thanks to you, gdiffor too, for this neat piece of code! If you don't mind, I'd like to use it in some of my upcoming stuff.
Thanks to both gdiffor and starway for the clean little function. I switched from the keyDown event to the keyUp event so the cursor advances right after the maximum number of characters for the textbox has been reached. I found that with the keyDown event, it only advanced when the first character for the next textbox was stroked. This was a little confusing for users that actually watched the cursor.
Sure tviman, you are free to use it (like everything else I post here). I just wonder why the one asked the question doesn't seem to show any interest in our discussion.
Well, it seems that our friend j420exe has found what it want but is a little hangry with the "thanks" word ;-) Water is not bad as soon as it stays out human body ;-)
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.