1

Ok so i have a jQuery .change

$('#application').change(function(){
var selected = $(this).val().trim();
alert(selected);
if(selected == 'something') {
  $('#profile-info').show();
}
....
....

my html

<select name="application" id="application">
<option value="--select something--">--select something--</option>
<option value="first">first</option>
<option value="second">second</option>
<option value="third">third</option></select>

The alert fires on all browsers but IE.....ie8 and 7 dont work at all

any ideas what i might be missing

Matt Elhotiby
  • 43,028
  • 85
  • 218
  • 321

2 Answers2

5

This is because the method "trim" is not supported in anything below IE9.

If you get rid of the trim, it works just fine:

$('#application').change(function(){
    var selected = $.trim($(this).val());
    alert(selected);
    if(selected == 'something') {
      $('#profile-info').show();
    }
});

Check the error console in the IE developer tools (press F12) to see the javascript error you are receiving.

Check out my example working in IE8: http://jsfiddle.net/Ku8HL/1/.

EDIT: jQuery actually has a trim method, so you can use $.trim to accomplish the same thing. IE8 and below do not have a trim method on the String object. I've updated the code above and the jsfiddle to include the jQuery trim method.

SoWeLie
  • 1,381
  • 12
  • 16
0

IE does not play nice with this situation. As per this SO question, you should listen for click.

Edit: Apparently my eyes decided IE8 is IE7 today.

Community
  • 1
  • 1
Aaron
  • 4,634
  • 1
  • 27
  • 43