?
Solved

JS: document.getElementById(var).style.display - Object needed error in IE8 only

Posted on 2010-08-21
3
Medium Priority
?
568 Views
Last Modified: 2012-06-27
I'm iterating through an array of strings (ids) and passing each element of the array to a function which either hides that element by id or shows it.

 
for(var tag = 0; tag < idtagArray.length; tag++){UpdateImage( idtagArray[tag], xmlhttp.responseText);}


    function UpdateImage( usediv, data )
    {
        if( data == null || data.length <= 0 ) {
            update_value.innerText = 0;
            return;
        }
     // [A5:1][A6:1][A7:1][A8:1]
        var start       = data.indexOf( "[" + usediv + ":" ) + 2 + usediv.length ;
        var end         = data.indexOf( "]", start );
        var data_value  = data.slice( start , end ) ;
     
     if( data_value > 0 )
     {
      document.getElementById(usediv).style.display = "";
     }
     else
     {
      document.getElementById(String(usediv)).style.display = "none";
     }
    }

Open in new window


The error is with getElementById - Object Needed. This only occurs on IE8; Mozilla and Chrome are fine. I even tried casting the parameter into a string with no success.
0
Comment
Question by:Chipkin_com
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 38

Expert Comment

by:Tom Beck
ID: 33493930
Can you provide an example of the values of 'usediv' and 'data' as passed to UpdateImage?
0
 

Author Comment

by:Chipkin_com
ID: 33494145
Yes, here is how i call the method:
var idtagArray = ["KT501-1_8","KT502-15_30","KT503-15_37","KT504-10_30","KT505-30_80","KT506-30_90","KT507-20_50","KT510-15_1440","KT512-0_1_2_3_4","KT513-30_80","KT514-0_1","KT520-0_1","KT525-0_1_2","KT526-0_1","KT527-0_9999","KT529-0_9999","KT531-0_9999","KT533-0_9999","KT535-0_250","KT536-0_9999","KT538-0_9999","KT548-0_1","KT549-0_1","KT550-102_120",
"KT551-80_98","KT552-15_37","KT553-0_30","KT554-50_90","KT555-20_50","KT565-0_10","KT566-0_20","KT567-0_30","KT568-0_50","KT569-1_10","KT570-1_10","KT571-2_10","KT572-2_10","KT573-1_20","KT574-1_30"];
for(var tag = 0; tag < idtagArray.length; tag++){UpdateImage( idtagArray[tag], xmlhttp.responseText);

Open in new window

0
 

Accepted Solution

by:
Chipkin_com earned 0 total points
ID: 33494319
Figured out my problem. Not all ids in the array were present on my page. Thank you.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article offers some helpful and general tips for safe browsing and online shopping. It offers simple and manageable procedures that help to ensure the safety of one's personal information and the security of any devices.
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
This Micro Tutorial will demonstrate how nuggets on the Web are formatted by using Chrome Developer Tools. These tools would not only view the site's CSS but it can also modify it and save the CSS to use on your own site.
Suggested Courses

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question