Safari count/length problem

radiobutton 1
radiobutton 2
radiobutton 3

So What exactly is the problem?

Aparently, Safari treats the 'length' property as a variable, but does not reset it's value.
The first time, it will count the number of elements correctly (in this example 3 + 1 = 4)
The second time it does not reset the previous count and adds the new number of items to the previous time it counted.

In the example above, Safari counts 3 radio buttons the first time. After adding 1 radiobutton, it counts 4 radiobuttons, but
adds that to the previously counted 3 (resulting in 7) the second time.. 7 + 5 = 12, .. 12 + 6 = 18, 18 + 7 = 25 and so on, and so on..

Update february 16, 2004: Dave Hyatt of Surfin' Safari (http://weblogs.mozillazine.org/hyatt/index.html)
notes; "I have fixed the count problem. That was a cool bug. :) We're looking into the keypress problem too."



Safari key-press event..

Safari seems to treat key-press events a bit different than other browsers.
Although Safari's approach is (in my opinion) more logical, it causes some problems on sites where an 'autotab' is put on a field.
I discovered this problem on a Dutch banking-site (www.postbankzakelijk.nl) where it caused my mother a lot of headaches

Safari's approach:
key-press -> the characters are counted -> the character is entered in the textfield 
Other browsers (IE, Mozilla):
key-press -> enter the character in the textfield -> the characters are counted

The problem: using the key-press event

Safari correctly 'tabs' to the next textfield if three (3) characters are entered in the first field
Also because of Safari's behaviour, it is impossible to change the entered characters once they've been entered!
(trying to use backspace to delete a character won't work!)

Other browsers will show 4 characters in the left field and then tab to the next field.

The cursor should jump to the second input when the first field contains 4 characters



The "workaround": use the key-up event

The solution for this problem is quite simple; check the number of characters in the field using the key-up event.
Because the key-up event takes place after the character has been entered (no matter what browser is used) there will be no problem!

All browsers (IE, Mozilla -and- Safari)
key-press -> the character is entered in the textfield  -> key-up -> the characters are counted

And here on the key-up:
All browsers correctly 'tab' to the next textfield if the left field contains 4 characters

The cursor moves to the second input when the first field contains 4 characters:



I hope this information is useful for anybody.
You can always contact me by email:

safariproblem_PLACE_'AT'_HERE_gone.nl

Sebastiaan van Stijn