Click to See Complete Forum and Search --> : Simple javascript needed for HTML form


danb
02-26-2003, 05:10 AM
Hi just wondering if someone could tell me how to do the following. (To say my Javascript skills are non-existent would be the understatement of the year!)

Here's the problem...

I have a simple HTML form, in which there are two text-box input fields - one for hour, the other for minute.

All I (i.e. my boss) wants to do is allow users to type in two digits into the hour box which should be a number between '00' and '23', after which focus will be switched to the minute box where a user may enter a number between '00' and '59'.

Forcing numbers to lie within the ranges is not imperative, since this may be done with server-side scripting upon submission.

The important part is that of the focus changing after two digits have been entered.

Thanks very much in advance. Much appreciated

Dan

gil davis
02-26-2003, 06:32 AM
<form ...>
<input name="i1" type="text" onkeydown="if(this.value.length>=1){this.form.i2.focus()}"><br>
<input name="i2" type="text" onkeydown="if(this.value.length>=1){this.form.i1.focus()}">
</form>
There are other things to consider. If you change the focus back and forth and there are already two digits there, what are you going to do?

danb
02-26-2003, 08:54 AM
Cheers Gil,

I am a total novice when it comes to Javascript, so how do I deal with the problem of revisiting the first input box once two characters have been entered?

Again, thanks very much for the assistance.