cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <a href="http://stackoverflow.com/questions/38622851/disable-options-already-selected-in-another-multiple-select-box/38622947" target="_black" class="source"><b>stackoverflow</b> . <i>Disable options already selected in another multiple select box</i> </a>


<select class='testA' multiple>
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="opel">Opel</option>
  <option value="audi">Audi</option>
</select>

<select class='testB' multiple>
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="opel">Opel</option>
  <option value="audi">Audi</option>
</select>


<span class="edit">----- UPDATE: option 2 with checkbox ------</span>

<div class="group">
<input id="car1-volvo" class="car1" type="checkbox" name="car1" value="volvo">
<label for="car1-volvo">volvo</label>

<input id="car1-saab" class="car1" type="checkbox" name="car1" value="saab">
<label for="car1-saab">saab</label>

<input id="car1-open" class="car1" type="checkbox" name="car1" value="opel">
<label for="car1-open">opel</label>

<input id="car1-audi" class="car1" type="checkbox" name="car1" value="audi">
<label for="car1-audi">audi</label>
</div>

<div class="group">
<input id="car2-volvo" class="car2" type="checkbox" name="car2" value="volvo">
<label for="car2-volvo">volvo</label>

<input id="car2-saab" class="car2" type="checkbox" name="car2" value="saab">
<label for="car2-saab">saab</label>

<input id="car2-open" class="car2" type="checkbox" name="car2" value="opel">
<label for="car2-open">opel</label>

<input id="car2-audi" class="car2" type="checkbox" name="car2" value="audi">
<label for="car2-audi">audi</label>
</div>
            
          
!
            
              $safeArea: 0.5rem;

body {
	font-family: sans-serif;
}

.source, .edit {
	display: block;
   padding: 1rem;
}

.source {
	text-decoration: none;
	opacity: 0.8;
	&:hover { opacity: 1; }
}

.edit {
	font-family: monospace;
	color: gray;
}

b {font-weight: 600;}
i {font-style: italic;}

a {
display: block;
margin: 2rem;
}

select {
	margin: 1rem;
}

.group {
	float: left;
	padding: 1rem;
}

label {
    display: block;
    width: 100px;
    height: auto;
    line-height: 1.2;
    cursor: pointer;
    position: relative;
    padding: $safeArea;
    border: 1px solid gray;
	
	&:not(first-of-type) {
		margin-top: -1px;
	}

    &:hover {
        background: #afafaf;
    }
}


input[type=checkbox] {
	display: none;
    &:checked + label:before {
        box-shadow: 0 0 0 1px gray;
        background-color: blue;
    }

    &:checked + label {
        color: white;
		 background: #008080;
    }
	
	 &:disabled + label {
		color: #afafaf;
	}

}
            
          
!
            
              var testA;
var testB;
var testBallow = [];
	 
$('.testA').on('change', function() {
	  testA = $(this).val();
	  $('.testB').val(testA);
 });


$('.testB').on('change', function() {
     testB = $(this).val();
	  var newValue = testB[testB.length - 1];
	
	 let difference = testB.filter(x => testA.indexOf(x) == -1);
	if ( difference.length > 0) {
		
		$('.testA').val(testB);
		testA = $('.testA').val();
	} else {
		 $(this).val(testA);
	}

 });



// ---- option 2

// 2 arguments: the first group of cars and the other group of cars
function selectCar(carInputs, otherCarInputs) {
	carInputs.each(function(){
		if ($(this).is(":checked")) { 
		  //  it is checked
			var value = $(this).val();
			console.log('checked: '+ value );
			
			//filter otherCarsInputs and disable the one that the user selected.
			otherCarInputs.filter(function(){
				if(this.value === value) {
					return true;
				} 
			}).prop('disabled', 'disabled');
			
		} else {
			var value = $(this).val();
			console.log('unchecked: '+ value );
			
			//do the inverse. is the user uncheck the input, enable it on the other team
			otherCarInputs.filter(function(){
				if ($(this).is(':disabled') && this.value == value) {
					return true;
				}
			}).prop('disabled', '');
		}
	});
}

$('input').on('change', function(){
	if ($(this).hasClass('car1') ) {
			selectCar($('.car1'), $('.car2'));
	} else {
		selectCar($('.car2'), $('.car1'));
	}
});



            
          
!
999px
Loading ..................

Console