Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Aug 3rd, 2013  |  syntax: None  |  size: 1.42 KB  |  views: 21  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. $('.mySelect').change(function(index, elem){
  2.     var myFilter = $(this).val();
  3.     if(myFilter !="selectOne"){
  4.         var size = $('.qSelect').not(this).not(function(index){
  5.         return $(this).val() != myFilter;
  6.     }).size();
  7.         if(size > 0){
  8.             alert("already selected.");
  9.         } else {
  10.             // do something
  11.         }  
  12.     }  
  13. });
  14.  
  15. <select name="select1" class="mySelect">
  16.     <option value="selectOne">Select one</option>
  17.     <option value="1">Option 1</option>
  18.     <option value="2">Option 2</option>
  19.     <option value="3">Option 3</option>
  20. </select>
  21.  
  22. <select name="select2" class="mySelect">
  23.     <option value="selectOne">Select one</option>
  24.     <option value="1">Option 1</option>
  25.     <option value="2">Option 2</option>
  26.     <option value="3">Option 3</option>
  27. </select>  
  28.  
  29. <select name="select3" class="mySelect">
  30.     <option value="selectOne">Select one</option>
  31.     <option value="1">Option 1</option>
  32.     <option value="2">Option 2</option>
  33.     <option value="3">Option 3</option>
  34. </select>
  35.        
  36. $('.mySelect').bind('change', function(el) {
  37.  
  38.     var _this = $(this),
  39.         newVal = _this.val();
  40.     $('select.mySelect:not([name=' + _this.attr('name') + '])
  41.             option[value=' + _this.data('oldVal') + ']').attr('disabled', false);
  42.     $('select.mySelect:not([name=' + _this.attr('name') + '])
  43.             option[value=' + newVal + ']').attr('disabled', true);
  44.     _this.data('oldVal', newVal);
  45.  
  46. });
clone this paste RAW Paste Data