![]() (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. Firefox, on the other hand, correctly tells you that the variable “fullAddress” is null. The result is the same in both cases, even though the first example shouldn’t work. In the second example, I’m targeting it the proper way via the actual id. #Javascript iexplorer code#In the first code block, I’m targeting the element via the id attribute that has a value of “full_address”. Var fullAddress = document.getElementById("address") 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") ![]() 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. 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. Often, form inputs will have both a name attribute and id specified. The name and id Attributes for Non-Grouped Form Inputs The truth is, I have never had much of an issue at all getting getElementById to work cross-browser, but after doing some quick research, it seems there are a few things to keep in mind with regards to Internet Explorer. Well, I’m not claiming to provide the perfect solution/article/resource here, but I thought I would post a few quick points on Internet Explorer’s handling of the getElementById method that might help a few people. And since the users seem to be searching through dozens of web pages looking for a solution to their particular problem, then obviously the pages discussing this JavaScript method are either too confusing or don’t specifically provide a practical solution. ![]() It is obvious that developers - likely beginners - are having issues getting the proper results when utilizing the getElementById method available in JavaScript, particularly in Internet Explorer versions 6 and 7. That’s not a very good ranking for that search phrase - yet somehow people are still finding one of my pages through that search. Not to mention the fact that the article that comes up doesn’t really address this issue directly. If you type this phrase into Google, Impressive Webs currently comes in at around result 115. One search phrase that leads surfers to my site pretty much every day is something along the lines of “getElementById explorer 7”. I’m flattered, and I hope I can continue to publish useful articles that will assist people and help with the exchange of ideas and techniques. Every week this website gets about 700 unique visits from Google searches, mostly from people searching for solutions to problems with JavaScript and CSS. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |