...

View Full Version : For in not working in IE7



spyke01
08-28-2008, 07:39 PM
Hey guys,
I do all my coding in FF and then check things out and bug fix in IE, i had some code that worked great on IE6 but is broken in IE7 heres the code:



function updateMenu(mytype, partid) {
try {
var i, myarray;
var price, difference;
var myarray = Parts[mytype];

// No need to look up which index the part has since we use the id itself.
// Calculate differences
var numKeys=0 // Let's see if there's more than one option, since the .length property won't be useable.
for(var i in myarray){
numKeys++
if(numKeys>1){break}
}
if(numKeys==0){
return // Uh, no parts?
}
else if(numKeys==1){
if(document.all) {
document.all[mytype].checked = true;
document.all[mytype].className = 'customizedisabled';
}
else if(document.getElementById) {
document.getElementById(mytype).checked = true;
document.getElementById(mytype).className = 'customizedisabled';
}
}
else {
for(var i in myarray) { // Now we must use for...in since the index range is not from 0 to n, but has holes.

price = "";
if(i != partid) { // Don't calculate difference for selected item (the difference is 0)
difference = myarray[i] / priceMask - myarray[partid] / priceMask;
if(difference > 0) price = " [+" + difference + "]";
else price = " [" + difference + "]";

}
if(document.all) {
document.all['pd' + i + mytype].innerHTML = price;
}
else if(document.getElementById) {
document.getElementById('pd' + i + mytype).innerHTML = price;
}
}
}
}
catch(er) {
}
}


Whats going on is that IE is breaking on the for(var i in myarray) loops, it runs throught the loop however i is always empty. I verified that the myarray variable is getting its data correctly by doing alert(myarray.length); and it is returning as expected.

Any ideas why the for in would be breaking?

spyke01
09-03-2008, 04:52 PM
*bump*

BarrMan
09-03-2008, 04:55 PM
if(document.all) {
document.all[mytype].checked = true;
document.all[mytype].className = 'customizedisabled';
}
else if(document.getElementById) {
document.getElementById(mytype).checked = true;
document.getElementById(mytype).className = 'customizedisabled';
}


Use the same code for FF and IE.
IE knows the command getElementById.

Also, What's Parts? Maybe the error comes from there.

spyke01
09-03-2008, 09:02 PM
Parts is an Array set outside the function looks like this:


var priceMask = 702343;
var basePrice = 1865;
var baseDiscount = 0.00;
var Parts = new Array();
var PartNames = new Array();
Parts[30] = new Array();
Parts[30][105] = 24582005;
PartNames[105] = 'No Biometrics';
Parts[30][163] = 73043672;
PartNames[163] = 'Included USB Biometric FingerPrint Scanner';
Parts[21] = new Array();
Parts[21][134] = 0;
PartNames[134] = '';
Parts[21][135] = 104649107;
PartNames[135] = '';
Parts[11] = new Array();
Parts[11][80] = 0;
PartNames[80] = 'No Virus or Spyware Protection';
Parts[11][81] = 52675725;
PartNames[81] = 'Premium Virus & Spyware Protection Package Install';
Parts[1] = new Array();
Parts[1][160] = 161538890;
PartNames[160] = 'AMD Dual Core Athlon 64 X2 4200+ 64Bit Advanced Processor';
Parts[1][141] = 238796620;
PartNames[141] = 'AMD Dual Core Athlon 64 X2 4800+ 64Bit Advanced Processor';

function init() {
SetDiagramPosition();

id30 = 163;
startUpdate(30, 163);

id21 = 134;
startUpdate(21, 134);

id11 = 80;
startUpdate(11, 80);

id1 = 141;
startUpdate(1, 141);

updatePrices();
}


Ive included the code for how its called. Thanks for info on getElementById the code was written several years ago is finally breaking :)

spyke01
09-11-2008, 05:10 PM
even this very basic code will not function in IE7, any ideas?

var array;

array['something'] = 'foo';
array['somethingelse'] = 'bar';
for (var keyVar in array) {
alert(keyVar + '--' + array[keyVar]);
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum