473,698 Members | 2,690 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with getting javascript to run correctly in firefox

67 New Member
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 1888
chanshaw
67 New Member
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: divSelectCatego ry 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 Contributor
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 Recognized Expert Moderator MVP
The problem is line 35. divSelectCatego ry hasn't been defined anywhere.
Jun 9 '09 #4
chanshaw
67 New Member
@RamananKaliraja n

No that part seems to be working (as far as I can see)
Jun 9 '09 #5
chanshaw
67 New Member
@acoder
In my html I have a div with the id divSelectCatego ry, shouldnt that mean it's defined? (new to javascript sorry)
Jun 9 '09 #6
acoder
16,027 Recognized Expert Moderator MVP
No. You need to access it with:
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("divSelectCategory")
Jun 9 '09 #7
chanshaw
67 New Member
@acoder
oh duh, thanks so much! :D
Jun 9 '09 #8
acoder
16,027 Recognized Expert Moderator MVP
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
16028
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" on the pop-up's form I want the pop-up to close & a new page to load in the "parent" window/page. I have this working in IE but cannot get it to work in Firefox. The parent window correctly loads the new page after submitting from the pop-up,...
2
2439
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 UK, the tz is set to 0 which is correct. If I run it on a US server, it initially returns -1, but in IE if I do a ctrl-refresh, it correctly gets it as 0. Any ideas ? <?php if (!isset($_GET)) print "
6
9339
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 yy=dataNow.getYear();
32
5013
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 not a function" ---------------------------------------------------- I have this in a .js file and in the head section.
37
6331
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, without getting a alert message that ask if u want to close the window. This did NOT happen in Internet Explorer 6, Mozilla firefox or other browsers.
11
2445
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"> ..historylinks {
16
2329
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 on the same page work correctly. It appears to be isolated to 1-2 machines in a particular network. I cannot verify whether these machines have had virus/spyware scans, but I do know the user is running Firefox 2.1 and IE 7 with the same...
12
2584
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 than one line and the text simply overlaps the sub-menus below it. I thought i had got around this by placing empty 'spacers' like so; oFoldMenu.make('sub3','')//spacer unfortunately, i have just viewed the site in IExplorer and it has added...
4
5049
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 value then put it back as the oncontextmenu attribute. Here's an example page if you want to try it out... <html> <head> <titletesting </title> <script><!--
10
2092
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 the javascript window.open method. Removing the Google Toolbar fixes the problem.
0
8683
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9170
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8901
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4371
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2336
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.