473,385 Members | 1,523 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.

xml.onload javascript problem for Firefox

Hi everyone, I'm having problem with the sequence of execution for xml.onload. It works fine if your not passing parameters to onload event but my code needs to pass parameter to its function. I'm able to research ablut passing parameters for onload event.

However my problem is it only executes on the last instance of loading the XML.

I'm sure ur all pretty confused. I'll show some of the javascript code:

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. var xmlDoc;
  3.  
  4. Load_XML("Organizations.xml", "organization_");
  5. Load_XML("Restrictions.xml", "restrictions_");  
  6. Load_XML("Country.xml", "country_");  
  7.  
  8. function Load_XML(XMLfilePath, Prop)  
  9.  
  10. {    //IE
  11.             if (window.ActiveXObject)
  12.               {       
  13.               xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  14.               xmlDoc.async=false;
  15.               xmlDoc.onreadystatechange = function ()
  16.               {
  17.     if (xmlDoc.readyState == 4)
  18.     {
  19.     displayDecoded_Value(Prop);
  20.     }
  21.  
  22.               }
  23.              }         
  24.  
  25.             else if (document.implementation && document.implementation.createDocument)
  26.  
  27.               {        //Firefox
  28.               xmlDoc=document.implementation.createDocument("","",null);
  29.               xmlDoc.onload = function (evt) { displayDecoded_Value(Prop); }
  30.               }
  31.  
  32.               xmlDoc.load(XMLfilePath)
  33.  
  34. }
  35.  
  36. function displayDecoded_Value(prop)
  37.     {
  38.             //code here to decode the values, includes looping to the child nodes of the XML documents and assigning the matched value to a variable
  39.     }
  40.  
I have here 3 instances to load the XML. Each XML is loaded, the DecodeValues function is used to decode the values based on the parameter passed.

In IE, the sequence of execution is that, First LoadXML is executed and calls on to the function LoadXML, then checks the browser used. If IE is used, the onreadystatechanged is executed and checks if it is equal to 4 and calls the DecodeValues function and loads the XML document. After executing the DecodeValues function, it goes back to execute the Second LoadXML. and so on. There's no problem here.

In Firefox, the sequence of execution is that, First LoadXML is executed and calls on to the function LoadXML, then checks the browser used. If Firefox is used, the onload event is called. In here I passed a parameter to the DecodeValues function. But the problem here is the DecodeValues function is only called at the last instance of LoadXML which is the Third LoadXML. So the only property that is decoded is the Third LoadXML, the country property.

Is my onload event syntax correct for Firefox???

Can anyone help me???

Really appreciate it..thanks/
Jan 21 '08 #1
3 3888
acoder
16,027 Expert Mod 8TB
In Firefox, the sequence of execution is that, First LoadXML is executed and calls on to the function LoadXML, then checks the browser used. If Firefox is used, the onload event is called. In here I passed a parameter to the DecodeValues function. But the problem here is the DecodeValues function is only called at the last instance of LoadXML which is the Third LoadXML. So the only property that is decoded is the Third LoadXML, the country property.
xmlDoc is global, so when you call the function three times, it only deals with the last one. Use it locally within the function.
Jan 21 '08 #2
xmlDoc is global, so when you call the function three times, it only deals with the last one. Use it locally within the function.

I understand...But how am I gonna code this??? additional help would be appreciated...thanks..
Jan 21 '08 #3
acoder
16,027 Expert Mod 8TB
Remove "var xmlDoc;" from line 2 (in the code in the first post) and move it in between lines 10 and 11.
Jan 21 '08 #4

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

Similar topics

6
by: Brian | last post by:
Hi everyone, I'm writing a function (in javascript) that needs to do one thing if the page has not loaded, and another (different) thing if the page has already loaded. I'm looking for a way...
2
by: laredotornado | last post by:
Hello, I am looking for a cross-browser way (Firefox 1+, IE 5.5+) to have my Javascript function execute from the BODY's "onload" method, but if there is already an onload method defined, I would...
4
by: stevong | last post by:
It works on Konquerer though. I remember it works on IE too. I've tried window.close() too. Doesn't work on Firefox also. I've also tried to create a function. It doesnt work on Firefox also....
1
by: KPS | last post by:
I'm attempting to create a simple treeview-like behavior in JavaScript. The desired behavior happens in IE but I cannot get the same to happen in FireFox. The primary thing I want to accomplish...
1
by: jamierphelps | last post by:
I'm sure you guys are tired of seeing this kind of message, but this is hopefully something a little different. I searched first. I am using Drupal for a site and I also want to use Nifty Corners...
3
by: jon | last post by:
Hello, I've had long standing code that runs in IE, that I'm testing with firefox unsuccessfully now. The problem seems to be that images that I dynamically create don't fire their onload event...
5
by: amit | last post by:
Hello, the javascript I'm using is not embedded into HTML but included. When I looking at w3schools.com it uses examples with js embedded into html. Anyway, when I use: function load() {...
7
by: Andrew Poulos | last post by:
In the head of my page I have: <script type="text/javascript" src="scripts/test.js"></script> and later in the head I have: <script type="text/javascript"> window.onload = function() { foo...
1
by: jodyxha | last post by:
Hi I use javascript to write a <img>-Element with a onload-attribute. In Firefox this onload function is called, but in IE7 it is not called. On the other hand a hardcoded <img>-Element with...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...

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.