Click to See Complete Forum and Search --> : curser moving automatically between fields on a form


laria
12-06-2002, 11:40 PM
I am creating a form and would like the cursor to automatically jump to the next field - especially when entering a phone number that I've set up as a 3+3+4 type of thing. How would I accomplish this?

Thanks in advance! :)

Stefan
12-07-2002, 09:30 AM
You could use the maxlength attribute on <input> from where your JavaScript could get the size.
http://www.w3.org/TR/html4/interact/forms.html#adef-maxlength

eg
<input size="3" maxlength="3">
<input size="3" maxlength="3">
<input size="4" maxlength="4">

It also prevents people from entering too many numbers in 1 field even if JS is not available (but they have to press tab manually to jump to the next input box of cource =)

Stefan
12-07-2002, 01:05 PM
Originally posted by Dave Clark
Note to laria: If you care about those who use NS4, you will have to do as I suggested above. In other words, the maxlength attribute, mentioned, does not work in that browser/version (maybe others, too).

Dave

Just out of interest, wouldn't a javascript be able to get the value of maxlenght even if the browser doesn't implement the correct behaviour in the HTML? :confused:

Stefan
12-07-2002, 04:57 PM
Originally posted by Dave Clark
NS4 will only allow new properties that are created from within JavaScript itself.


:(

It's stuff like that makes you glad NS 4 is on the way to die out :)

laria
12-07-2002, 06:54 PM
well yeah.. I wasn't thinking that I had to worry about dated versions of browsers. I thought about it afterwards too and most people are used to tabbing between fields and to throw something different at the general population is usually devastating to them anyway ;) People like 'same ole same ole'.
Thank you all for taking the time to respond. I appreciate it :)