Alright this runs just fine in IE but in firefox I get nothing -
function startup()
-
{
-
if (window.ActiveXObject)
-
{
-
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
-
}
-
else if (document.implementation.createDocument)
-
{
-
xmlDoc=document.implementation.createDocument("","",null);
-
}
-
else
-
{
-
alert('Your browser cannot handle this script');
-
}
-
if (xmlDoc!=null)
-
{
-
xmlDoc.async=false;
-
xmlDoc.load("XML/faq.xml");
-
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);
-
-
}
-
}
-
-
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>
-
-
thanks for your time.
8 1883
After doing some more debugging I tried to tune the code a little -
<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>
-
-
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
Hi i think the problem may be in the line - xmlDoc.onload = readFile();
-
xmlDoc.load("XML/faq.xml");
Can you please check on this.
Regards
Ramanan Kalirajan
The problem is line 35. divSelectCategory hasn't been defined anywhere.
@acoder
In my html I have a div with the id divSelectCategory, shouldnt that mean it's defined? (new to javascript sorry)
No. You need to access it with: - document.getElementById("divSelectCategory")
No problem. Glad it's working :)
Sign in to post your reply or Sign up for a free account.
Similar topics
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"...
|
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...
|
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...
|
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...
|
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,...
|
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">...
|
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...
|
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...
|
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...
|
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...
|
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$) {
}
...
|
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...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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,...
| |