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
- itemSlots=new Array();
- itemSlots[0]="head";
- itemSlots[1]="shoulders";
- ...
- itemSlots[16]="relic";
- //called by the button to select gear
- function selectGear(gear)
- {
- switch(gear)
- {
- case "lvl":
- for (j0=0; j0<itemSlots.length; j0++)
- {
- document.itemForm.elements[itemSlots[j0]].selectedIndex = 1;
- loadItem(document.itemForm.elements[itemSlots[j0]],itemSlots[j0])
- }
- break;
- }
- }
- //loads each item, ignore the unlock step
- function loadItem(itemID,slot)
- {
- //special flag called by selecting the last item
- unlockItemFlag=0;
- //unlocks slot with user input
- if(itemID.options[itemID.selectedIndex].value =="7")unlockSlot(slot);
- if(unlockItemFlag==0)lockSlot(slot);
- //loads file for each item
- var xmlFileLocation = ('items/'+itemID.options[itemID.selectedIndex].value + '.xml')
- loadXML(xmlFileLocation,1,slot);
- }
- //XML Loading
- function loadXML(xmlFile,type,slot)
- {
- if (detectBrowser()=="IE")
- {
- xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
- xmlDoc.onreadystatechange = function ()
- {
- if (xmlDoc.readyState == 4)
- {
- switch(type)
- {
- case 0:
- for(k=0; k<itemSlots.length; k++)
- {
- loadItemsIntoMenus(itemSlots[k]);
- }
- break;
- case 1:
- loadItemStats(slot,xmlDoc);
- break;
- case 2:
- fillBox();
- break;
- }
- }
- };
- xmlObj=xmlDoc.documentElement;
- }
- else if (detectBrowser()=="FF")
- {
- xmlDoc = document.implementation.createDocument("", "", null);
- xmlDoc.load(xmlFile);
- xmlDoc.onload=function()
- {
- switch(type)
- {
- case 0:
- for(k=0; k<itemSlots.length; k++)
- {
- loadItemsIntoMenus(itemSlots[k]);
- }
- break;
- case 1:
- loadItemStats(slot,xmlDoc);
- break;
- case 2:
- fillBox();
- break;
- }
- };
- }
- else
- {
- alert("you can't handle this script! please use firefox or internet explorer")
- }
- xmlDoc.load(xmlFile);
- }
- //disregard the massive quantity of XML interpretations
- function loadItemStats(slot,xmlDoc)
- {
- //clearItemValues(slot);
- slotNum=slotTextToNum(slot);
- //reset item to zeros
- relicManaReduction=0;
- itemCrit[slotNum]=0;
- itemHit[slotNum]=0;
- itemInt[slotNum]=0;
- itemStam[slotNum]=0;
- itemDmg[slotNum]=0;
- itemMp5[slotNum]=0;
- itemHaste[slotNum]=0;
- socketNumber=0;
- if(slot=="head")metaFlag=0;
- socketFlag=0;
- //check for sockets
- if (xmlDoc.getElementsByTagName('socket') != null)
- {
- var socketInfo = xmlDoc.getElementsByTagName('socket');
- for (k5=0; k5<socketInfo.length; k5++)
- {
- socketFlag=1;
- socketColors[k5]=socketInfo[k5].getAttribute("color")
- if (socketColors[k5]== "Meta")
- {
- metaFlag=1;
- }
- socketNumber=k5+1;
- //unlocks gems
- document.itemForm.elements[slot+"Gem"+socketNumber].disabled=false;
- }
- //lock out and disable empty sockets
- for (socketsEmpty=k5+1; socketsEmpty <=3; socketsEmpty++)
- {
- if(unlockItemFlag==0)document.itemForm.elements[slot+"Gem"+socketsEmpty].disabled=true;
- }
- }
- newGemLoader(slot);
- // alert(xmlDoc.getElementsByTagName("bonusIntellect").item(0).firstChild.data)
- //check for int
- if (xmlDoc.getElementsByTagName("bonusIntellect").item(0) != null)
- {
- itemInt[slotNum]=xmlDoc.getElementsByTagName("bonusIntellect").item(0).firstChild.data*1;
- }
- //check for stam
- if (xmlDoc.getElementsByTagName("bonusStamina").item(0) != null)
- {
- itemStam[slotNum]=xmlDoc.getElementsByTagName("bonusStamina").item(0).firstChild.data*1;
- }
- //check for crit
- if (xmlDoc.getElementsByTagName("bonusCritSpellRating").item(0) != null)
- {
- itemCrit[slotNum]=xmlDoc.getElementsByTagName("bonusCritSpellRating").item(0).firstChild.data*1;
- }
- //check for hit
- if (xmlDoc.getElementsByTagName("bonusHitSpellRating").item(0) != null)
- {
- itemHit[slotNum]=xmlDoc.getElementsByTagName("bonusHitSpellRating").item(0).firstChild.data*1;
- }
- //check for haste
- if (xmlDoc.getElementsByTagName("bonusHasteSpellRating").item(0) != null)
- {
- itemHaste[slotNum]=xmlDoc.getElementsByTagName("bonusHasteSpellRating").item(0).firstChild.data*1;
- }
- //itemDamage[slot]=xmlDoc.getElementsByTagName("spellData").item(1).firstChild.data)
- for (k=0; xmlDoc.getElementsByTagName('desc')[k] != null; k++)
- {
- //alert(xmlDoc.getElementsByTagName('desc')[k].lastChild.data);
- itemData=xmlDoc.getElementsByTagName('desc')[k].lastChild.data
- //Check for +Damage
- if (itemData.match("Increases damage and healing done by magical spells and effects by up to"))
- {
- itemDmg[slotNum]=parseFloat(itemData.substring(itemData.length-4,itemData.length-1));
- }
- //Check for Mana Regen
- else if (itemData.match("Restores "))
- {
- itemMp5[slotNum]=parseFloat(itemData.substring(9,12));
- }
- //check for LB/CL dmg
- else if(itemData.match("Increases damage done by Chain Lightning and Lightning Bolt by up to "))
- {
- itemDmg[slotNum]=parseFloat(itemData.substring(itemData.length-3,itemData.length-1));
- }
- else if(itemData.match("Reduces the mana cost of") && itemData.match("Lightning"))
- {
- relicManaReduction=parseFloat(itemData.substring(itemData.length-3,itemData.length-1));
- }
- else
- {
- }
- }
- calculateItemStats(slot,slotNum);
- outputItemStats(slot,slotNum);
- // 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])
- }
- function calculateItemStats(slot,slotNum)
- {
- totalItemStam[slotNum]=itemStam[slotNum]+itemEnchantStam[slotNum]+itemGem1Stam[slotNum]+itemGem2Stam[slotNum]+itemGem3Stam[slotNum];
- totalItemInt[slotNum]=itemInt[slotNum]+itemEnchantInt[slotNum]+itemGem1Int[slotNum]+itemGem2Int[slotNum]+itemGem3Int[slotNum];
- totalItemDmg[slotNum]=itemDmg[slotNum]+itemEnchantDmg[slotNum]+itemGem1Dmg[slotNum]+itemGem2Dmg[slotNum]+itemGem3Dmg[slotNum];
- totalItemCrit[slotNum]=itemCrit[slotNum]+itemEnchantCrit[slotNum]+itemGem1Crit[slotNum]+itemGem2Crit[slotNum]+itemGem3Crit[slotNum];
- totalItemHit[slotNum]=itemHit[slotNum]+itemEnchantHit[slotNum]+itemGem1Hit[slotNum]+itemGem2Hit[slotNum]+itemGem3Hit[slotNum];
- totalItemMp5[slotNum]=itemMp5[slotNum]+itemEnchantMp5[slotNum]+itemGem1Mp5[slotNum]+itemGem2Mp5[slotNum]+itemGem3Mp5[slotNum];
- totalItemHaste[slotNum]=itemHaste[slotNum]+itemEnchantHaste[slotNum]+itemGem1Haste[slotNum]+itemGem2Haste[slotNum]+itemGem3Haste[slotNum];
- }
- function outputItemStats(slot,slotNum)
- {
- document.itemForm.elements[slot+"Stam"].value=totalItemStam[slotNum];
- document.itemForm.elements[slot+"Int"].value=totalItemInt[slotNum];
- document.itemForm.elements[slot+"Dmg"].value=totalItemDmg[slotNum];
- document.itemForm.elements[slot+"Crit"].value=totalItemCrit[slotNum];
- document.itemForm.elements[slot+"Hit"].value=totalItemHit[slotNum];
- document.itemForm.elements[slot+"Mp5"].value=totalItemMp5[slotNum];
- document.itemForm.elements[slot+"Haste"].value=totalItemHaste[slotNum];
- }
Thanks in advance for your help,
-Rob