getElementById problem (in internet explorer)
getElementById problem (in internet explorer) a few quick points on Internet Explorer’s handling of the getElementById method (cross-browser)
Often, form inputs will have both a name attribute and id specified. To prevent problems with getElementById, make sure the value for the name attribute for a non-grouped form element is the same as the value for the id attribute for that same element.
Do This:
Don’t Do This:
The reason you should do this is because in Internet Explorer, if you’re trying to target an element using getElementById, for some reason that browser will search the name attribute of certain elements on the page, in addition to the id. Assuming we’ve used the wrong method for coding the name and id values, the code blocks below will get the exact same result in IE7:
var fullAddress = document.getElementById("full_address");
alert(fullAddress.value);
var fullAddress = document.getElementById("address");
alert(fullAddress.value);
In the first code block, I’m targeting the element via the id attribute that has a value of “full_address”. In the second example, I’m targeting it the proper way via the actual id. The result is the same in both cases, even though the first example shouldn’t work. Firefox, on the other hand, correctly tells you that the variable “fullAddress” is null.
(NOTE: I neglected to mention in the above section that I was specifically talking about non-grouped elements with the same name and id attributes. Radio buttons and checkboxes obviously have to share the “name” attribute, so if they had ids then there would be differences. See comments section for more.)
This problem is very similar to the issue above, so I won’t go into great detail. To avoid problems with getElementById in Internet Explorer, don’t put a name attribute on the