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

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;
     // [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 = "";
      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.
Who is Participating?
Chipkin_comConnect With a Mentor Author Commented:
Figured out my problem. Not all ids in the array were present on my page. Thank you.
Tom BeckCommented:
Can you provide an example of the values of 'usediv' and 'data' as passed to UpdateImage?
Chipkin_comAuthor Commented:
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",
for(var tag = 0; tag < idtagArray.length; tag++){UpdateImage( idtagArray[tag], xmlhttp.responseText);

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.