www.webdeveloper.com
Results 1 to 2 of 2

Thread: This script works fine in IE but not in Firefox

  1. #1
    Join Date
    Jun 2009
    Posts
    1

    This script works fine in IE but not in Firefox

    Hey I'm having trouble here the following code only runs in IE

    Code:
    		<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>
    In Firefox the error console gives me a

    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

  2. #2
    Join Date
    Jun 2009
    Posts
    111
    Looks to me like divSelectCategory is not defined.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles