Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

getElementById javascript with IE7

Avatar of bman21
bman21 asked on
JavaPHPWeb Browsers
4 Comments1 Solution993 ViewsLast Modified:
i have a javascript that displays a button next to a variable in website.  The website updates constantly and after awhile, my button disappears altogether or takes it a very long time to load.  i googled the heck out of this and found many references to a problem on how IE handles the getElementByID function that i currently am using.

The error that my google search explained to me was that the error occurs because IE7 doesn't handle the getElementByID function properly.  instead of searching the id field, IE7 also searches another field, and if either are the same or doesn't exist, the code breaks.

Attached is a portion of the code that i have the getElementById implemented.  Also, within the code i have the workaround that everyone seems to mention after the google search.  Right now it is commented out because it does not work (the buttons do not display).  

This is an urgent matter and any help is greatly appreciated.  attached is the snippet
for ( pai in idsAry )
                sid = idsAry[pai];
//              button = "<input type=button style='border: 0px;' id='button" + sid + "' value='+' border='0' onclick=checkPriors('" + sid + "')>";
                button = "<img src='images/report-icon.gif' id='button" + sid + "' border='0' onclick=checkPriors('" + sid + "')>";
                /*if (/msie/i.test(navigator.userAgent)) //only overide IE
                         //alert("IT WORKED");
                        document.nativeGetElementById = document.getElementByID;
                        document.getElementById = function(id)
                                var elem = document.nativeGetElementById(id);
                                        //make sure that it is a valid match on id
                                        if(elem.attributes['id'].value == id)
                                                return elem;
                                                //alert("it worked");
                                                //otherwise find the correct element
                                                for(var i=1;i<document.all[id].length;i++)
                                                        if(document.all[id][i].id == id)
                                                                return document.all[id][i];
                                return null;
                document.getElementById(sid).innerHTML = button;//debugger breaks here after the page refreshes
Avatar of ludofulop

Our community of experts have been thoroughly vetted for their expertise and industry experience.

This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answers