0

I have a jquery script that is used to show/hide values depending on another select box and although it works in Firefox and Chrome, it doesn't work in IE

var otherselectoption = $('#select1,#select2,#select3').find('option').filter(function(){
  return $(this).attr('value') != "";
});
 $('#selectlist').change(function(){
   var selected = $(this).val();
   otherselectoption.hide().filter(function(){
     return $(this).attr('value').indexOf(selected) > -1;
   }).show();
 });

Link to demo here: http://jsfiddle.net/8g13wc5g/

Also, I would like it so each time i select the "---Filter---" option the rest of the bottom 3 select boxes reset to the default value to be blank with full set of options.

user3436467
  • 1,763
  • 1
  • 22
  • 35
  • That fiddle doesnt work for me in Chrome – Tom Doodler Aug 25 '15 at 06:46
  • 1
    You could use this trick - http://stackoverflow.com/a/5414366; but I would advise against it. It will be an overkill. Just stick to disabling the options for IE as shown in my last answer - http://stackoverflow.com/a/32184116/1355315 – Abhitalks Aug 25 '15 at 07:07
  • @Abhitalks, actually i used the trick you mentioned and customised it a bit and it works really well - here is my version of it http://fiddle.jshell.net/u83t19kc/ – user3436467 Aug 25 '15 at 14:43

1 Answers1

0

You can not do that in IE. You can rather disable/enable the options instead of hide/show in case of IE. Other solution would be to add/remove options instead of show/hide. But that is not feasible over enable/disable options solution.

Second part of your question you can add prop('selected', true) to set the relevant options selected

var otherselectoption = $('#select1,#select2,#select3').find('option');
$('#selectlist').change(function(){
  var selected = $(this).val();
  otherselectoption.prop('disabled', true);
  otherselectoption.filter(function(){
    return ($(this).attr('value').indexOf(selected) > -1 ||$(this).attr('value') == "")
 }).prop({'disabled': false});
}).change();
Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125