Hey I'm having trouble here the following code only runs in IE
In Firefox the error console gives me aCode:<script type="text/javascript"> var categories = new Array(); var questions = new Array(); var xmlDoc=null; var firstTime; var sizeOfCats; var sizeOfQues; function readFile() { if (xmlDoc!=null) { var x=xmlDoc.getElementsByTagName("QUES"); for (i=0;i<x.length;i++) { t = x[i].getElementsByTagName("CAT")[0].childNodes[0].nodeValue; categories.push(t); } var categoryList = categories.unique(); for (var i=categoryList.length-1; i>=0; --i ) { selectCategory.options[i]=new Option(categoryList[i], i, true, false); } sizeOfCats = selectCategory.options.length; selectCategory.options[sizeOfCats]=new Option("Select", sizeOfCats, true, true); } } function startup() { divSelectCategory.innerHTML = "<select id=\"selectCategory\" onchange=\"loadSelectQuestion()\"></select>"; if (window.ActiveXObject) { xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async=false; xmlDoc.load("XML/faq.xml"); readFile(); } else if (document.implementation.createDocument) { xmlDoc = document.implementation.createDocument("", "", null); xmlDoc.onload = readFile(); xmlDoc.load("XML/faq.xml"); } else { alert('Your browser cannot handle this script'); } } Array.prototype.unique = function() { var r = new Array(); o:for(var i = 0, n = this.length; i < n; i++) { for(var x = 0, y = r.length; x < y; x++) { if(r[x]==this[i]) { continue o; } } r[r.length] = this[i]; } return r; } function clearSelect() { selectQuestion.options.length = 0; } function loadSelectQuestion() { questions = []; theAnswer.innerHTML=""; var theCategory = selectCategory.options[selectCategory.selectedIndex].text; if(theCategory != "Select") { divSelectQuestion.innerHTML = "<p>Select a Question:</p><select id=\"selectQuestion\" onchange=\"loadAnswer()\"></select><br/><br/>"; var x=xmlDoc.getElementsByTagName("QUES"); for (i=0;i<x.length;i++) { aCategory = x[i].getElementsByTagName("CAT")[0].childNodes[0].nodeValue; if(aCategory == theCategory) { aQuestion = x[i].getElementsByTagName("Q")[0].childNodes[0].nodeValue; questions.push(aQuestion); for (var j=questions.length-1; j>=0; --j ) { selectQuestion.options[j]=new Option(questions[j], j, true, false) } } else { } } sizeOfQues = selectQuestion.options.length; selectQuestion.options[sizeOfQues]=new Option("Select", sizeOfQues, true, true); } else { divSelectQuestion.innerHTML = ""; } } function loadAnswer() { var theQuestion = selectQuestion.options[selectQuestion.selectedIndex].text; var x=xmlDoc.getElementsByTagName("QUES"); for (i=0;i<x.length;i++) { aQuestion = x[i].getElementsByTagName("Q")[0].childNodes[0].nodeValue; if(aQuestion == theQuestion) { anAnswer = x[i].getElementsByTagName("A")[0].childNodes[0].nodeValue; theAnswer.innerHTML = "Answer:<br/><br/>" + anAnswer + "<br/><br/>"; } } } </script>
Error: divSelectCategory is not defined
Source File: file:///C:/Users/Administrator/Desktop/CRC/crcFAQ.html
Line: 42
Can anyone help with the solution to my problem? Thanks for your time


Reply With Quote
Bookmarks