473,385 Members | 2,015 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Problem with getting javascript to run correctly in firefox

Alright this runs just fine in IE but in firefox I get nothing

Expand|Select|Wrap|Line Numbers
  1.             function startup()
  2.             {
  3.                 if (window.ActiveXObject)
  4.                 {
  5.                     xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  6.                 }
  7.                 else if (document.implementation.createDocument)
  8.                 {
  9.                     xmlDoc=document.implementation.createDocument("","",null);
  10.                 }
  11.                 else
  12.                 {
  13.                     alert('Your browser cannot handle this script');
  14.                 }    
  15.                 if (xmlDoc!=null)
  16.                 {
  17.                     xmlDoc.async=false;
  18.                     xmlDoc.load("XML/faq.xml");
  19.                     var x=xmlDoc.getElementsByTagName("QUES");
  20.                     for (i=0;i<x.length;i++)
  21.                     {
  22.                         t = x[i].getElementsByTagName("CAT")[0].childNodes[0].nodeValue;
  23.                         categories.push(t);
  24.                     }
  25.                     var categoryList = categories.unique();
  26.  
  27.                     for (var i=categoryList.length-1; i>=0; --i )
  28.                     {
  29.                         selectCategory.options[i]=new Option(categoryList[i], i, true, false);
  30.                     }
  31.  
  32.                     sizeOfCats = selectCategory.options.length;
  33.                     selectCategory.options[sizeOfCats]=new Option("Select", sizeOfCats, true, true);
  34.  
  35.                 }
  36.             }
  37.  
  38.             Array.prototype.unique = function()
  39.             {
  40.                 var r = new Array();
  41.                 o:for(var i = 0, n = this.length; i < n; i++)
  42.                 {
  43.                     for(var x = 0, y = r.length; x < y; x++)
  44.                     {
  45.                         if(r[x]==this[i])
  46.                         {
  47.                             continue o;
  48.                         }
  49.                     }
  50.                     r[r.length] = this[i];
  51.                 }
  52.                 return r;
  53.             }
  54.  
  55.             function clearSelect()
  56.             {
  57.                 selectQuestion.options.length = 0;
  58.             }
  59.  
  60.             function loadSelectQuestion()
  61.             {
  62.                 questions = [];
  63.                 theAnswer.innerHTML="";
  64.                 var theCategory = selectCategory.options[selectCategory.selectedIndex].text;
  65.                 if(theCategory != "Select")
  66.                 {
  67.                     divSelectQuestion.innerHTML = "<p>Select a Question:</p><select id=\"selectQuestion\" onchange=\"loadAnswer()\"></select><br/><br/>";
  68.                     var x=xmlDoc.getElementsByTagName("QUES");
  69.                     for (i=0;i<x.length;i++)
  70.                     {
  71.                         aCategory = x[i].getElementsByTagName("CAT")[0].childNodes[0].nodeValue;
  72.  
  73.                         if(aCategory == theCategory)
  74.                         {
  75.                             aQuestion = x[i].getElementsByTagName("Q")[0].childNodes[0].nodeValue;
  76.                             questions.push(aQuestion);
  77.                             for (var j=questions.length-1; j>=0; --j )
  78.                             {
  79.                                 selectQuestion.options[j]=new Option(questions[j], j, true, false)
  80.                             }
  81.                         }
  82.                         else
  83.                         {
  84.  
  85.                         }
  86.                     }
  87.  
  88.                 sizeOfQues = selectQuestion.options.length;
  89.                 selectQuestion.options[sizeOfQues]=new Option("Select", sizeOfQues, true, true);
  90.  
  91.                 }
  92.                 else
  93.                 {
  94.                     divSelectQuestion.innerHTML = "";
  95.                 }
  96.             }
  97.  
  98.             function loadAnswer()
  99.             {
  100.                 var theQuestion = selectQuestion.options[selectQuestion.selectedIndex].text;
  101.                 var x=xmlDoc.getElementsByTagName("QUES");
  102.                 for (i=0;i<x.length;i++)
  103.                 {
  104.                     aQuestion = x[i].getElementsByTagName("Q")[0].childNodes[0].nodeValue;
  105.  
  106.                     if(aQuestion == theQuestion)
  107.                     {
  108.                         anAnswer = x[i].getElementsByTagName("A")[0].childNodes[0].nodeValue;
  109.                         theAnswer.innerHTML = "Answer:<br/><br/>" + anAnswer + "<br/><br/>";
  110.                     }
  111.                 }
  112.             }
  113.  
  114.         </script>
  115.  
  116.  
thanks for your time.
Jun 8 '09 #1
8 1883
After doing some more debugging I tried to tune the code a little

Expand|Select|Wrap|Line Numbers
  1.         <script type="text/javascript">
  2.             var categories = new Array();
  3.             var questions = new Array();
  4.             var xmlDoc=null;
  5.             var firstTime;
  6.             var sizeOfCats;
  7.             var sizeOfQues;
  8.  
  9.             function readFile()
  10.             {
  11.                 if (xmlDoc!=null)
  12.                 {
  13.                     var x=xmlDoc.getElementsByTagName("QUES");
  14.                     for (i=0;i<x.length;i++)
  15.                     {
  16.                         t = x[i].getElementsByTagName("CAT")[0].childNodes[0].nodeValue;
  17.                         categories.push(t);
  18.                     }
  19.                     var categoryList = categories.unique();
  20.  
  21.                     for (var i=categoryList.length-1; i>=0; --i )
  22.                     {
  23.                         selectCategory.options[i]=new Option(categoryList[i], i, true, false);
  24.                     }
  25.  
  26.                     sizeOfCats = selectCategory.options.length;
  27.                     selectCategory.options[sizeOfCats]=new Option("Select", sizeOfCats, true, true);
  28.  
  29.                 }
  30.  
  31.             }
  32.  
  33.             function startup()
  34.             {
  35.                 divSelectCategory.innerHTML = "<select id=\"selectCategory\" onchange=\"loadSelectQuestion()\"></select>";
  36.  
  37.                 if (window.ActiveXObject)
  38.                 {
  39.                     xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  40.                     xmlDoc.async=false;
  41.                     xmlDoc.load("XML/faq.xml");
  42.                     readFile();
  43.                 }
  44.                 else if (document.implementation.createDocument)
  45.                 {                     
  46.                      xmlDoc = document.implementation.createDocument("", "", null);
  47.                       xmlDoc.onload = readFile();
  48.                      xmlDoc.load("XML/faq.xml");
  49.                 }
  50.                 else
  51.                 {
  52.                     alert('Your browser cannot handle this script');
  53.                 }
  54.             }
  55.  
  56.             Array.prototype.unique = function()
  57.             {
  58.                 var r = new Array();
  59.                 o:for(var i = 0, n = this.length; i < n; i++)
  60.                 {
  61.                     for(var x = 0, y = r.length; x < y; x++)
  62.                     {
  63.                         if(r[x]==this[i])
  64.                         {
  65.                             continue o;
  66.                         }
  67.                     }
  68.                     r[r.length] = this[i];
  69.                 }
  70.                 return r;
  71.             }
  72.  
  73.             function clearSelect()
  74.             {
  75.                 selectQuestion.options.length = 0;
  76.             }
  77.  
  78.             function loadSelectQuestion()
  79.             {
  80.                 questions = [];
  81.                 theAnswer.innerHTML="";
  82.                 var theCategory = selectCategory.options[selectCategory.selectedIndex].text;
  83.                 if(theCategory != "Select")
  84.                 {
  85.                     divSelectQuestion.innerHTML = "<p>Select a Question:</p><select id=\"selectQuestion\" onchange=\"loadAnswer()\"></select><br/><br/>";
  86.                     var x=xmlDoc.getElementsByTagName("QUES");
  87.                     for (i=0;i<x.length;i++)
  88.                     {
  89.                         aCategory = x[i].getElementsByTagName("CAT")[0].childNodes[0].nodeValue;
  90.  
  91.                         if(aCategory == theCategory)
  92.                         {
  93.                             aQuestion = x[i].getElementsByTagName("Q")[0].childNodes[0].nodeValue;
  94.                             questions.push(aQuestion);
  95.                             for (var j=questions.length-1; j>=0; --j )
  96.                             {
  97.                                 selectQuestion.options[j]=new Option(questions[j], j, true, false)
  98.                             }
  99.                         }
  100.                         else
  101.                         {
  102.  
  103.                         }
  104.                     }
  105.  
  106.                 sizeOfQues = selectQuestion.options.length;
  107.                 selectQuestion.options[sizeOfQues]=new Option("Select", sizeOfQues, true, true);
  108.  
  109.                 }
  110.                 else
  111.                 {
  112.                     divSelectQuestion.innerHTML = "";
  113.                 }
  114.             }
  115.  
  116.             function loadAnswer()
  117.             {
  118.                 var theQuestion = selectQuestion.options[selectQuestion.selectedIndex].text;
  119.                 var x=xmlDoc.getElementsByTagName("QUES");
  120.                 for (i=0;i<x.length;i++)
  121.                 {
  122.                     aQuestion = x[i].getElementsByTagName("Q")[0].childNodes[0].nodeValue;
  123.  
  124.                     if(aQuestion == theQuestion)
  125.                     {
  126.                         anAnswer = x[i].getElementsByTagName("A")[0].childNodes[0].nodeValue;
  127.                         theAnswer.innerHTML = "Answer:<br/><br/>" + anAnswer + "<br/><br/>";
  128.                     }
  129.                 }
  130.             }
  131.  
  132.         </script>
  133.  
  134.  
Now this works in IE but in firefox it doesn't...
the error the error console gives is

Error: divSelectCategory is not defined
Source File: file:///C:/Users/Administrator/Desktop/CRC/crcFAQ.html
Line: 42

Anyways hope that helps you to help me :D
Jun 9 '09 #2
RamananKalirajan
608 512MB
Hi i think the problem may be in the line

Expand|Select|Wrap|Line Numbers
  1.   xmlDoc.onload = readFile(); 
  2.   xmlDoc.load("XML/faq.xml"); 
Can you please check on this.

Regards
Ramanan Kalirajan
Jun 9 '09 #3
acoder
16,027 Expert Mod 8TB
The problem is line 35. divSelectCategory hasn't been defined anywhere.
Jun 9 '09 #4
@RamananKalirajan

No that part seems to be working (as far as I can see)
Jun 9 '09 #5
@acoder
In my html I have a div with the id divSelectCategory, shouldnt that mean it's defined? (new to javascript sorry)
Jun 9 '09 #6
acoder
16,027 Expert Mod 8TB
No. You need to access it with:
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("divSelectCategory")
Jun 9 '09 #7
@acoder
oh duh, thanks so much! :D
Jun 9 '09 #8
acoder
16,027 Expert Mod 8TB
No problem. Glad it's working :)
Jun 9 '09 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: fogwolf | last post by:
First a basic outline of what I am trying to do: I want to have a page spawn a pop-up when you click "submit" on its form. On this pop-up page there will be another form. When you click "submit"...
2
by: Adrian Parker | last post by:
I have a php page which uses checks to see if the tz variable is in the argument list.. if not, it recalls the page using javascript with the added tz argument.. if I run it locally here in the...
6
by: Franz | last post by:
Hy all, I have a problem with a date in javascript on firefox Browser. I use this javascript method: var dataNow=new Date(); var dd=dataNow.getDate(); var mm=dataNow.getMonth()+1; var...
32
by: paul | last post by:
HI! I keep on getting this error and I have tried different things but I am not sure how to send the expiring date. The error that I am getting in Firefox 1.5 is "Error: expires.toGMTString is...
37
by: Jan Tovgaard | last post by:
Hey everyone:) We have a critical problem, which I can see that other people also has ran into. In Internet Explorer 7 it is no longer possible to do a window.close after opening a window,...
11
by: jesdynf | last post by:
I'm having trouble applying a stylesheet to content I'm generating after the fact. Here's the sample code: <html> <head> <title>CSS/DOM Problem Example</title> <style type="text/css">...
16
by: Eric | last post by:
I have a user of a web application written in Java/JSP that is unable to login to the site simply because certain links on the page do not run when they are clicked. Other popups using Javascript...
12
by: tim | last post by:
I am using foldoutmenu 3 and am having problems with viewing my menus in firefox. On my sub3 menus i have more than one line of text in some places. firefox does not recognise that there is more...
4
by: ICPooreMan | last post by:
I've got some code which works in firefox that's giving me fits in IE7 (maybe other versions too I haven't tested it). What I want to do is get the oncontextmenu attribute of something, change the...
10
by: Steve | last post by:
Just a warning to the group. The Google Toolbar causes Firebug to issue lots of "Too much recursion" errors in the toolbar.js and eventual causes my Firefox browser to stop responding when using...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.