473,395 Members | 1,974 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,395 software developers and data experts.

JavaScript, Multiple XML file loading problem, FF/IE

10
Hello everyone,

Long time lurker, first time poster. I'm a beginner coder, and I've taught myself everything with the help and expertise of users and websites like this one. I normally figure out any problem, but this one really has me stumped.

Basically, I have created a site that initially loads a set of "items" and their values into 17 drop down menus from an XML file. Each of those "items" when selected from the drop down menu loads data into a few arrays, and outputs it to a table. The data is then used for a calculation output, which is the overall goal of the program/site.

Everything works fine up to this point...

Now I'm introducing a button that automatically selects the 17 "items." So basically my application runs through a loop and is supposed to: select each item, load each XML file, interprets each "items" data, save each "item" data to arrays, and then outputs each to the table.

It works fine locally with internet explorer 6, but does not work with Firefox online/local, or IE online. If I add an "alert" somewhere in the loop process, it works, but then I have 17 alerts to deal with. IE online only inputs the last item in the table, and Firefox outputs all 0's locally, and then online Firefox implements mostly all zeros, except for the last and first(which outputs the data of the last instead of the first).

So anyway, my source code is about 2000 lines. You can access my program at http://www.stasistech.com/wow/test/itemdps.html (click the max "i.lvl" button to see the problem)
js: http://www.stasistech.com/wow/test/itemdps.js

Here's the code that somewhere has the problem(i hope!):
Expand|Select|Wrap|Line Numbers
  1. itemSlots=new Array();
  2. itemSlots[0]="head";
  3. itemSlots[1]="shoulders";
  4. ...
  5. itemSlots[16]="relic";
  6.  
  7. //called by the button to select gear
  8. function selectGear(gear)
  9.     {
  10.     switch(gear)
  11.         {
  12.         case "lvl":
  13.             for (j0=0; j0<itemSlots.length; j0++)
  14.                 {
  15.                 document.itemForm.elements[itemSlots[j0]].selectedIndex = 1;
  16.                 loadItem(document.itemForm.elements[itemSlots[j0]],itemSlots[j0])
  17.                 }
  18.             break;
  19.         }    
  20.     }    
  21.  
  22. //loads each item, ignore the unlock step
  23. function loadItem(itemID,slot)
  24.     {
  25. //special flag called by selecting the last item
  26. unlockItemFlag=0;
  27.     //unlocks slot with user input
  28.     if(itemID.options[itemID.selectedIndex].value =="7")unlockSlot(slot); 
  29.     if(unlockItemFlag==0)lockSlot(slot);
  30.     //loads file for each item
  31.     var xmlFileLocation = ('items/'+itemID.options[itemID.selectedIndex].value + '.xml')
  32.     loadXML(xmlFileLocation,1,slot);
  33.     }
  34.  
  35. //XML Loading
  36. function loadXML(xmlFile,type,slot)
  37.     {
  38.     if (detectBrowser()=="IE")
  39.         {
  40.         xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
  41.         xmlDoc.onreadystatechange = function () 
  42.             {
  43.             if (xmlDoc.readyState == 4) 
  44.                 {
  45.                 switch(type)
  46.                     {
  47.                     case 0:
  48.                         for(k=0; k<itemSlots.length; k++)
  49.                             {
  50.                             loadItemsIntoMenus(itemSlots[k]);
  51.                             }    
  52.                         break;
  53.                     case 1:
  54.                         loadItemStats(slot,xmlDoc);
  55.                         break;
  56.                     case 2:    
  57.                         fillBox();
  58.                         break;
  59.                     }
  60.                 }    
  61.             };    
  62.         xmlObj=xmlDoc.documentElement;
  63.         }
  64.  
  65.     else if (detectBrowser()=="FF")
  66.         {
  67.         xmlDoc = document.implementation.createDocument("", "", null);
  68.         xmlDoc.load(xmlFile);
  69.         xmlDoc.onload=function()
  70.             {
  71.                 switch(type)
  72.                     {
  73.                     case 0:
  74.                         for(k=0; k<itemSlots.length; k++)
  75.                             {
  76.                             loadItemsIntoMenus(itemSlots[k]);
  77.                             }    
  78.                         break;
  79.                     case 1:
  80.                         loadItemStats(slot,xmlDoc);
  81.                         break;
  82.                     case 2:    
  83.                         fillBox();
  84.                         break;
  85.                     }
  86.             };    
  87.         }
  88.     else
  89.         {
  90.         alert("you can't handle this script! please use firefox or internet explorer")
  91.         }
  92.     xmlDoc.load(xmlFile);
  93.     }
  94.  
  95. //disregard the massive quantity of XML interpretations 
  96. function loadItemStats(slot,xmlDoc)
  97.     {
  98.     //clearItemValues(slot);
  99.     slotNum=slotTextToNum(slot);
  100.     //reset item to zeros
  101.     relicManaReduction=0;
  102.     itemCrit[slotNum]=0;
  103.     itemHit[slotNum]=0;
  104.     itemInt[slotNum]=0;
  105.     itemStam[slotNum]=0;
  106.     itemDmg[slotNum]=0;
  107.     itemMp5[slotNum]=0;
  108.     itemHaste[slotNum]=0;
  109.     socketNumber=0;
  110.     if(slot=="head")metaFlag=0;
  111.     socketFlag=0;
  112.  
  113.  
  114.     //check for sockets
  115.     if (xmlDoc.getElementsByTagName('socket') != null)
  116.         {
  117.         var socketInfo = xmlDoc.getElementsByTagName('socket');
  118.         for (k5=0; k5<socketInfo.length; k5++)
  119.             {
  120.             socketFlag=1;
  121.             socketColors[k5]=socketInfo[k5].getAttribute("color")
  122.             if (socketColors[k5]== "Meta")
  123.                 {
  124.                 metaFlag=1;
  125.                 }
  126.             socketNumber=k5+1;
  127.  
  128.  
  129.             //unlocks gems
  130.             document.itemForm.elements[slot+"Gem"+socketNumber].disabled=false;
  131.  
  132.             }
  133.         //lock out and disable empty sockets
  134.         for (socketsEmpty=k5+1; socketsEmpty <=3; socketsEmpty++)
  135.             {
  136.             if(unlockItemFlag==0)document.itemForm.elements[slot+"Gem"+socketsEmpty].disabled=true;        
  137.             }
  138.         }    
  139.         newGemLoader(slot);
  140. //    alert(xmlDoc.getElementsByTagName("bonusIntellect").item(0).firstChild.data)     
  141.     //check for int
  142.     if (xmlDoc.getElementsByTagName("bonusIntellect").item(0) != null)
  143.         {
  144.         itemInt[slotNum]=xmlDoc.getElementsByTagName("bonusIntellect").item(0).firstChild.data*1;
  145.         }
  146.  
  147.     //check for stam
  148.     if (xmlDoc.getElementsByTagName("bonusStamina").item(0) != null)
  149.         {
  150.         itemStam[slotNum]=xmlDoc.getElementsByTagName("bonusStamina").item(0).firstChild.data*1;
  151.         }
  152.  
  153.     //check for crit
  154.     if (xmlDoc.getElementsByTagName("bonusCritSpellRating").item(0) != null)
  155.         {
  156.         itemCrit[slotNum]=xmlDoc.getElementsByTagName("bonusCritSpellRating").item(0).firstChild.data*1;
  157.         }
  158.  
  159.     //check for hit
  160.     if (xmlDoc.getElementsByTagName("bonusHitSpellRating").item(0) != null)
  161.         {
  162.         itemHit[slotNum]=xmlDoc.getElementsByTagName("bonusHitSpellRating").item(0).firstChild.data*1;
  163.         }
  164.  
  165.     //check for haste
  166.     if (xmlDoc.getElementsByTagName("bonusHasteSpellRating").item(0) != null)
  167.         {
  168.         itemHaste[slotNum]=xmlDoc.getElementsByTagName("bonusHasteSpellRating").item(0).firstChild.data*1;
  169.         }
  170.  
  171.     //itemDamage[slot]=xmlDoc.getElementsByTagName("spellData").item(1).firstChild.data)
  172.     for (k=0; xmlDoc.getElementsByTagName('desc')[k] != null; k++)
  173.         {
  174.         //alert(xmlDoc.getElementsByTagName('desc')[k].lastChild.data);
  175.  
  176.         itemData=xmlDoc.getElementsByTagName('desc')[k].lastChild.data
  177.  
  178.         //Check for +Damage
  179.         if (itemData.match("Increases damage and healing done by magical spells and effects by up to"))
  180.             {
  181.             itemDmg[slotNum]=parseFloat(itemData.substring(itemData.length-4,itemData.length-1));
  182.             }
  183.         //Check for Mana Regen
  184.         else if (itemData.match("Restores "))
  185.             {
  186.             itemMp5[slotNum]=parseFloat(itemData.substring(9,12));
  187.             }
  188.         //check for LB/CL dmg
  189.         else if(itemData.match("Increases damage done by Chain Lightning and Lightning Bolt by up to "))
  190.             {
  191.             itemDmg[slotNum]=parseFloat(itemData.substring(itemData.length-3,itemData.length-1));
  192.             }
  193.         else if(itemData.match("Reduces the mana cost of") && itemData.match("Lightning"))
  194.             {    
  195.             relicManaReduction=parseFloat(itemData.substring(itemData.length-3,itemData.length-1));
  196.             }
  197.         else
  198.             {
  199.             }
  200.         }
  201.         calculateItemStats(slot,slotNum);    
  202.         outputItemStats(slot,slotNum);
  203. //    alert("int:\t" + itemInt[slotNum]+"\n\nstam:\t" + itemStam[slotNum] + "\n\ncrit:\t" + itemCrit[slotNum] + "\n\ndamage:\t" + itemDmg[slotNum] + "\n\nregen:\t" + itemMp5[slotNum])
  204.     }
  205. function calculateItemStats(slot,slotNum)
  206.     {
  207.     totalItemStam[slotNum]=itemStam[slotNum]+itemEnchantStam[slotNum]+itemGem1Stam[slotNum]+itemGem2Stam[slotNum]+itemGem3Stam[slotNum];
  208.     totalItemInt[slotNum]=itemInt[slotNum]+itemEnchantInt[slotNum]+itemGem1Int[slotNum]+itemGem2Int[slotNum]+itemGem3Int[slotNum];
  209.     totalItemDmg[slotNum]=itemDmg[slotNum]+itemEnchantDmg[slotNum]+itemGem1Dmg[slotNum]+itemGem2Dmg[slotNum]+itemGem3Dmg[slotNum];
  210.     totalItemCrit[slotNum]=itemCrit[slotNum]+itemEnchantCrit[slotNum]+itemGem1Crit[slotNum]+itemGem2Crit[slotNum]+itemGem3Crit[slotNum];
  211.     totalItemHit[slotNum]=itemHit[slotNum]+itemEnchantHit[slotNum]+itemGem1Hit[slotNum]+itemGem2Hit[slotNum]+itemGem3Hit[slotNum];
  212.     totalItemMp5[slotNum]=itemMp5[slotNum]+itemEnchantMp5[slotNum]+itemGem1Mp5[slotNum]+itemGem2Mp5[slotNum]+itemGem3Mp5[slotNum];
  213.     totalItemHaste[slotNum]=itemHaste[slotNum]+itemEnchantHaste[slotNum]+itemGem1Haste[slotNum]+itemGem2Haste[slotNum]+itemGem3Haste[slotNum];
  214.     }
  215.  
  216. function outputItemStats(slot,slotNum)
  217.     {
  218.     document.itemForm.elements[slot+"Stam"].value=totalItemStam[slotNum];
  219.     document.itemForm.elements[slot+"Int"].value=totalItemInt[slotNum];
  220.     document.itemForm.elements[slot+"Dmg"].value=totalItemDmg[slotNum];
  221.     document.itemForm.elements[slot+"Crit"].value=totalItemCrit[slotNum];
  222.     document.itemForm.elements[slot+"Hit"].value=totalItemHit[slotNum];
  223.     document.itemForm.elements[slot+"Mp5"].value=totalItemMp5[slotNum];
  224.     document.itemForm.elements[slot+"Haste"].value=totalItemHaste[slotNum];
  225.     }
  226.  
  227.  

Thanks in advance for your help,
-Rob
Jul 18 '07 #1
7 2984
psybert
10
Anyone have any guidance on what I should do? I've sort of hit a brick wall in the site programming until I can figure this problem out. Any help or direction would be greatly appreciated. Thanks again for your time,
-Rob
Jul 20 '07 #2
psybert
10
Anyone have any guidance on what I should do? I've sort of hit a brick wall in the site programming until I can figure this problem out. Any help or direction would be greatly appreciated. Thanks again for your time,
-Rob
Bump~ ! I figure it's the weekend, maybe It will get some more visibility.
Jul 21 '07 #3
drhowarddrfine
7,435 Expert 4TB
All I can add is that there are 132 HTML errors and no doctype so IE is in quirks mode.
Jul 22 '07 #4
psybert
10
All I can add is that there are 132 HTML errors and no doctype so IE is in quirks mode.
I went in and fixed all of them. Thanks for the tip. Unfortunately the page still doesn't work :(
Jul 22 '07 #5
kovik
1,044 Expert 1GB
If it works offline, but not online, maybe you're accessing the file incorrectly.

And if your code doesn't work at all in Firefox, then the code that you've specified in your FF branch is probably incorrect.
Jul 22 '07 #6
psybert
10
If it works offline, but not online, maybe you're accessing the file incorrectly.

And if your code doesn't work at all in Firefox, then the code that you've specified in your FF branch is probably incorrect.
The problem only comes about when i try to loop the whole process. If i change and add each item manually it comes up fine. In fact if I add an "alert" in the loop process, it slows it down enough to actually work.
Jul 23 '07 #7
psybert
10
anyone have any more ideas? :(
Jul 27 '07 #8

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

Similar topics

53
by: Cardman | last post by:
Greetings, I am trying to solve a problem that has been inflicting my self created Order Forms for a long time, where the problem is that as I cannot reproduce this error myself, then it is...
4
by: JesusFreak | last post by:
From: us_traveller@yahoo.com (JesusFreak) Newsgroups: microsoft.public.scripting.jscript Subject: toolbar script problem NNTP-Posting-Host: 192.92.126.136 Recently, I downloaded the following...
3
by: Roy Wang | last post by:
hi, My problem is how to determining when the XML file has loaded using javascript. I loaded an xml file using javascript in a web page. The code below is loading the xml file for IE:...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
3
by: jimmygoogle | last post by:
I posted earlier with a scope problem. I think I resolved it in IE but in Firefox it still exists. Anyone have any ideas/experience with this? I attached my code sorry it is so long. You can...
1
by: ozzy.osborn | last post by:
Hello All, I have been struggling with a cross browser solution to loading external javascript files on the fly. I have been successful using the following code in IE6: var newScr =...
22
by: Christopher Nelson | last post by:
I have a little menu system which essentially takes HTML like: <div id='foo'></div> and retrieves foo.shtml from the server and inserts it inside the <div>. But sometimes I'd like foo.shtml...
3
by: GroupReader | last post by:
I posted a similar question earlier and got lots of good feedback, but now I have more information: Problem: I have javascript in a user control that is not "loading" properly. When I try to...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.