ASU Web Community

jQuery in IE6

Thursday, April 24th, 2008 - 4:48 pm
  • bbailey1
  • bbailey1's picture

I am getting an error in IE6 when trying to select an option in a select box using:

$("#select option").attr("selected","selected"); // thats basically how i'm doing it, but you get the idea

I have also used the jQuery pluggin $.fn.selectOptions, but that has errored as well. We also tried using the DOM and selecting it old school, but that errored too.

Works fine with IE7 and FF. Anyone out there have any experience with this? Suggestions?

Tuesday, April 29th, 2008 - 11:28 am
  • cscholtz
  • cscholtz's picture

Hmmm not sure about the jQuery error but if there was also an error using plain vanilla JavaScript via the DOM then that might be a syntax error.  With the older browsers I sometimes find alternate lesser used methods that will work.  For example, getElementByName instead of getElementById.

cheers,

Cameron

Wednesday, April 30th, 2008 - 9:10 am
  • bbailey1
  • bbailey1's picture

Thanks Cameron,

It turns out that the problem wasn't that IE6 didn't like the attr("selected","selected") part. I ran that script seperately in IE6 and it worked just fine. It didn't like the fact that I was calling it inside of an AJAX call. The AJAX works fine and the script works fine, just not together.

If you are interested in what I was trying to do and how we overcame this obstacle:

We were loading a country select box with countries via AJAX. After you selected what country you were from, saved the app, then came back to that page, the select box was supposed to load the countries again (via AJAX) and then select the country that you chose the first time. IE6 didn't like that method.

Solution: Instead of loading the countries, then selecting the country, when we made the call to get the countries list, we also sent the country that was being selected. We then parsed out the list in an XSL and loaded the list with the option already selected.