PDA

View Full Version : Bug in Mac/IE when looping through a form?


bryndyment
04-28-2003, 08:16 PM
Could someone please confirm that this is merely a bug for Mac/IE?

Very simple JavaScript... looping through a form to check all the checkboxes at once. I've isolated the code to the bare minimum to demonstrate the bug.

Works great on IE/Netscape for Windows, but breaks in Macintosh. It's getting confused because the element name is a number, and when indexing the 'elements' array, it's getting confused between the element name and the element index.

http://www.hoologic.com/kanji/checkbox.htm

beetle
04-28-2003, 08:51 PM
It's generally not kosher to use a number for the name, or at least a numeric digit in the first position. By using a number only, you are asserting the retrieval of the element by index, and not by name.

Don't use number-only names.

bryndyment
04-28-2003, 09:06 PM
Thanks.

> you are asserting the retrieval of the element by index

IE/Mac is giving the name higher precedence when there's an operlap with the index, but IE/Netscape on Windows is giving the index higher precedence. By your comments, it sounds like IE/Mac is handling this incorrectly.

beetle
04-28-2003, 09:22 PM
Well, the problem is in the fact that browsers expose named for elements as properties of the form object. Properties cannot start with a numeric character

The browser sees bothe of these the same

document._form.elements[0]
document._form.elements['0']

Even though the 2nd is implented as a string -- the script engine retrieves that reference as an index (this is where the Mac verions messes up, apparently) -- otherwise, you might as well do this

document._form.0

Which is compeletely invalid.

So, long story short, don't use numbered names, or numbers in the first letter position.