spyke01
08-28-2008, 06: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?
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?