views:

36

answers:

2

I have the following code. The code populates a list box basing on the selection done. But my code works on IE 7 & fails on IE 6.

//----------------------------------------------------------------------------------------------
//fill the location list on the basis of Country

function FillLocationList()
{
    var opt =  document.createElement("OPTION");
    var selected =document.getElementById('drpCountryName').selectedIndex;
    var size = document.getElementById('drpCountryName').options.length;
     if(!event.ctrlKey && !event.shiftKey)
     {

        document.getElementById('drpLocation').options.length = 0;
        for(var i=0;i<locationArray.value.length;i++)
        {

            //if(document.getElementById('drpLocationReportsTo').value == locationArray.value[i].LocationRptId)
            if(document.getElementById('drpCountryName').value == locationArray.value[i].CountryCode)
            {
                 opt =  document.createElement("OPTION");
                 opt.text = locationArray.value[i].LocationName;
                 opt.value=locationArray.value[i].LocationId;
                 document.getElementById("drpLocation").options.add(opt);
            }
        }

     }


    else if(event.ctrlKey || event.shiftKey)
    {

        document.getElementById('drpLocation').length = 0;
        for(j=0;j<document.getElementById('drpCountryName').length;j++)
        {
           var currentLocation = document.getElementById('drpCountryName').options[j].value;
            if(document.getElementById('drpCountryName').options[j].selected)
            {   
                for(var i=0;i<locationArray.value.length;i++)
                {

                    if(currentLocation == locationArray.value[i].CountryCode)
                    {
                         opt =  document.createElement("OPTION");
                         opt.text = locationArray.value[i].LocationName;
                         opt.value=locationArray.value[i].LocationId;
                         document.getElementById("drpLocation").options.add(opt);
                    }
                }
            }
       }

    }

}
+1  A: 

Is the function fired under IE6? Because a common problem is to attach the function to the onclick event (which has problems under IE6).

Use onchange instead.

Eduardo Molteni
I haven't used onClick
JJ
A: 

If you are firing it from the onclick in IE6 try this, well if you are not already doing it this way. IE6 has some issues with firing javascript functions in the onclick event.

onclick="FillLocationList(); event.returnValue=false; return false;"

pete blair
It seems to be a intermittent problem as well, in some pages I have just done return false; and it works fine. In other situations it just doesn't work so I have to use this work around. Don't you love IE6.
pete blair
I've found that some delay or different internal execution path causes this intermittent problems.
Eduardo Molteni
Interesting, I will pay attention to the execution path next time I run into the issue. Thanks.
pete blair