Note that there are some explanatory texts on larger screens.

plurals
  1. POJavaScript error in IE7 & IE8: SCRIPT5007: Unable to get the value of property 'newQuestion': object is null or undefined
    primarykey
    data
    text
    <p>I've been looking all over and can't come up with a solution. The following code works perfectly in IE9, Chrome, FF, and Safari. However, when you hit "Start" in IE7 or IE8 you get the following error:</p> <pre><code>SCRIPT5007: Unable to get the value of property 'newQuestion': object is null or undefined </code></pre> <p>The code at issue is here:</p> <pre><code>//This is used to reduce some code size and not type document.getElementById(a) each time function DOMelem(a) { return document.getElementById(a); } //This is used to round numbers function roundTo(a,b) { a=a*Math.pow(10,b); a=Math.round(a); a=a/Math.pow(10,b); return a; } //The quiz object function sQuiz(a,c,init) { //This part is used to get the variable used by the user this.getName=function() { for(var v in window) { if(window[v] instanceof sQuiz) { this.varName=v; } } }, //This will create the first page of the quiz this.createQuiz=function() { this.getName(); DOMelem(a).innerHTML="&lt;h1&gt;"+init.intro.qTitle+"&lt;/h1&gt;"; DOMelem(a).innerHTML+="&lt;h2&gt;"+init.intro.qAuthor+"&lt;/h2&gt;"; DOMelem(a).innerHTML+="&lt;h3&gt;"+init.intro.qComments+"&lt;/h3&gt;&lt;br /&gt;&lt;br /&gt;"; DOMelem(a).innerHTML+="&lt;input type='button' value='Start' onClick='"+this.varName+".newQuestion(0)'&gt;"; }, //This one will create a random id for the quiz and create a bar for it this.createBar=function() { id="12391023103091"+Math.round(Math.random()*12391023103091); id=id.substr(id.length-14,14); this.randBarId=id; DOMelem(c).innerHTML="&lt;div class='progress_full' id='pro_"+id+"'&gt;&lt;div class='progress_bar' style='width:0%;' id='bar_"+id+"'&gt;&lt;/div&gt;&lt;/div&gt;"; }, //In this section we check to see if there's a bar, if we must show the results or just show the interface. this.newQuestion=function(index) { //Create the bar if it does not exist if(!DOMelem("pro_"+this.randBarId)||!DOMelem("bar_"+this.randBarId)) { eval(this.varName+".createBar()"); } //Show the results page if(index&gt;=init.questions.length) { eval(this.varName+".showResults()"); } //Show the question interface else { DOMelem(a).innerHTML="&lt;h1&gt;"+init.questions[index].question+"&lt;/h1&gt;"; for (var i=0;i&lt;init.questions[index].answers.length;i++) { DOMelem(a).innerHTML+="&lt;input type='button' name='"+index+"_"+i+"' value='"+init.questions[index].answers[i]+"' onClick='"+this.varName+".checkAnswer("+index+","+i+")'&gt;"; } DOMelem(a).innerHTML+="&lt;input type='submit' id='btn_"+this.randBarId+"' value='Next Question' onClick='"+this.varName+".changeQuestion("+index+")' disabled&gt;"; DOMelem("bar_"+this.randBarId).style.width=(((index+1)/init.questions.length)*100)+"%"; } }, //This is used when the user clicks to change the question this.changeQuestion=function(index) { return this.newQuestion(index+1); }, //This part handles when the user clicks on an answer, color it, un-disable the button and record the guess this.checkAnswer=function(index,i) { init.questions[index].guessed=i; var inputs=document.getElementById(a).getElementsByTagName("input"); for(var j=0;j&lt;inputs.length;j++) { document.getElementById(a).getElementsByTagName("input")[j].className=""; if(inputs[i].name==index+"_"+i) { document.getElementById(a).getElementsByTagName("input")[i].className="selected"; } } DOMelem("btn_"+this.randBarId).disabled=false; }, //This one here shows the result of the quiz. this.showResults=function() { DOMelem(a).innerHTML="&lt;h1&gt;Results of "+init.intro.qTitle+"&lt;/h1&gt;"; var count=0; for(var i=0;i&lt;init.questions.length;i++) { if(init.questions[i].guessed==(init.questions[i].correctAnswer-1)) { count++; DOMelem(a).innerHTML+="&lt;div id='answer' class='correct'&gt;&amp;radic; Question "+(i+1)+"&lt;/div&gt;"; } else { DOMelem(a).innerHTML+="&lt;div id='answer' class='wrong'&gt;&amp;times; Question "+(i+1)+"&lt;/div&gt;"; } } var result=roundTo((count/init.questions.length)*100,2); DOMelem(a).innerHTML+="&lt;h3 style='clear:both'&gt;&lt;br /&gt;"+result+"% correct answers.&lt;/h3&gt;"; var tweet=init.tweetText.replace(/--score--/gi,result+"%"); tweet=tweet.replace(/ /gi,'+'); tweet="https://www.twitter.com/share?text="+tweet; DOMelem(a).innerHTML+="&lt;a href='"+tweet+"'&gt;Tweet it&lt;/a&gt;"; } } </code></pre> <p>You can view a demo <a href="http://ktbaker.com/quiz" rel="nofollow">here</a>.</p> <p>I really think I've read about every related question, but still can't come up with a solution. Please let me know if any additional information would be helpful.</p> <p>UPDATE:</p> <p>To clarify, I am testing in IE9 with compatibility mode turned on. If anyone actually has IE7 or IE8 installed, I would live to know your results. Anyway, the code seems to execute up until here:</p> <pre><code> //This will create the first page of the quiz this.createQuiz=function() { this.getName(); DOMelem(a).innerHTML="&lt;h1&gt;"+init.intro.qTitle+"&lt;/h1&gt;"; DOMelem(a).innerHTML+="&lt;h2&gt;"+init.intro.qAuthor+"&lt;/h2&gt;"; DOMelem(a).innerHTML+="&lt;h3&gt;"+init.intro.qComments+"&lt;/h3&gt;&lt;br /&gt;&lt;br /&gt;"; DOMelem(a).innerHTML+="&lt;input type='button' value='Start' onClick='"+this.varName+".newQuestion(0)'&gt;"; }, </code></pre> <p>Once the start button is clicked, I get an error because <code>this.varName</code> returns as <code>undefined</code>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload