Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    May 2006
    Posts
    62
    Thanks
    0
    Thanked 0 Times in 0 Posts

    For in not working in IE7

    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:

    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?

  • #2
    New Coder
    Join Date
    May 2006
    Posts
    62
    Thanks
    0
    Thanked 0 Times in 0 Posts
    *bump*

  • #3
    Senior Coder BarrMan's Avatar
    Join Date
    Feb 2005
    Location
    Israel.
    Posts
    1,644
    Thanks
    69
    Thanked 83 Times in 82 Posts
    Code:
    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.
    Last edited by BarrMan; 09-03-2008 at 04:58 PM.

  • #4
    New Coder
    Join Date
    May 2006
    Posts
    62
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Parts is an Array set outside the function looks like this:
    Code:
    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

  • #5
    New Coder
    Join Date
    May 2006
    Posts
    62
    Thanks
    0
    Thanked 0 Times in 0 Posts
    even this very basic code will not function in IE7, any ideas?
    [highlight=javascript]
    var array;

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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •