I worked on a website recently where the following syntax worked under Internet Explorer 8 for accessing a form element:
document.form
However, no other browser that I am aware of accepts this syntax. I changed the syntax to this:
document.forms[0]
After making this simple change, it started working under Chrome, Safari, and Firefox, and continued to work under IE 8.
What weird bug would cause Internet Explorer to accept document.form as valid syntax?
Here's the way it was before I changed it:
// check for a name
if (document.form.a_name.value == "") {
alert("You must provide a first name.");
return false;
}
Here's what it looks like after I changed it:
// check for a name
if (document.forms[0].a_name.value == "") {
alert("You must provide a first name.");
return false;
}
The expression document.form appeared in many places on this website --- perhaps 25 or so. By making this one simple change, I made this site --- which is an old one --- cross-browser compatible.
What I find hard to understand is why document.form ever worked. Maybe it is just some weird Internet Explorer 8 bug
Ed Abbott