0

I have code written in JScript for a website I have implemented. The script is pretty straightforward, nothing too fancy. It works in Chrome and Firefox, but it does not execute in IE. I am getting the error

SSCRIPT5007: Unable to get the value of 'style': Object is null of undefined.

Now, I have already checked online for possible solutions. The one I see the most is that I need to include X-UA-Compatible in my meta tag, but it is already in there. Is there any other solution?

Specifically, my code fails at this part:

var extra_options = document.getElementsByName("myExtraOptions");
for(thisindex = 0; thisindex < 7; thisindex++) {
        extra_options[thisindex].style.display = 'none';
    }
user3334871
  • 1,251
  • 2
  • 14
  • 36

2 Answers2

1

You have to check if that element exists something like:

for(thisindex = 0; thisindex < 7; thisindex++) {
        if(extra_options[thisindex] !== undefined) {
            extra_options[thisindex].style.display = 'none';
        }
}

and you can check how many elements with that name exists:

var extra_options = document.getElementsByName("myExtraOptions");
alert(extra_options.length);
Snake Eyes
  • 16,287
  • 34
  • 113
  • 221
  • Okay, did that, and you were right, extra_options doesn't exist. Is there a difference between IE and Chrome/Firefox in declarations that will not allow me to do this? – user3334871 Jun 30 '14 at 14:25
  • I mean, I specifically created elements with the name "myExtraOptions", so I KNOW they exist. – user3334871 Jun 30 '14 at 14:26
  • No, is not difference between IE and Chrome because JS is same for these browsers. Read this: http://stackoverflow.com/questions/278719/getelementsbyname-in-ie7 – Snake Eyes Jun 30 '14 at 14:33
  • What are the types of the "myExtraOptions" elements? If they are not input elements (or something) you could expect to not get them, maibe using a className will get the desired results. – Prusse Jun 30 '14 at 15:41
-1

Try putting ClientIDMode="Static" in your page header.

asven
  • 133
  • 1
  • 7