I want to disable the values in combobox on selection for multiple comboboxes. Like i have a four combobox1, combobox2, combobox3, combobox4 with values Select,1,2,3,4 and 5. Now, if i select value '1' from combobox1, then it should be disabled from all other comboboxes. And then if i select '2' from combobox2, then it should be disabled in combobox1 and combobox3 with value '1' disabled in combobox3 also.
More clearly :
- Combobox1 - selected - value '1'
- Combobox2 - selected - value '2'
- Combobox3 - selected - value '3'
Now the result should be :
Combobox1 - Disabled values - '2','3' but not 1/3/4/5
Combobox2 - Disabled values - '1','3' but not 3/4/5
Combobox3 - Disabled values - '1','2' but not 3/4/5
Combobox4 - Disabled values - '1','2','3' but not 4/5
EDIT
If Combobox1 is selected with Option "Select" then it should disable all the other combobxes except combobox1 and reset all the values with 0 index for all other comboboxes.
But what happening with the code, when i select value 1 from combobox it is disabled for combobox 2 and 3, but when selecting value '2' from combobox2, the value '1' combobox3 gets enabled.
Here is what i have done so far :
HTML Code :
<head>
<title>Language test page</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<body>
<select name="g1" id="select_g1">
<option value="select1">Select</option>
<option value="one">one</option>
<option value="two">two</option>
<option value="three">three</option>
</select>
<select name="g2" id="select_g2">
<option value="select2">Select</option>
<option value="one">one</option>
<option value="two">two</option>
<option value="three">three</option>
</select>
<select name="g3" id="select_g3">
<option value="select3">Select</option>
<option value="one">one</option>
<option value="two">two</option>
<option value="three">three</option>
</select>
</body>
</html>
JQuery Code :
<script>
$(document).ready(function(){
$('select').on('change', function (e) {
$('select option').prop('disabled', false);
var optionSelected = $("option:selected", this);
var valueSelected = this.value;
$("select option:contains('" + valueSelected + "')").each(function(){
if(valueSelected === this.value){
this.disabled = true;
}else{
this.disabled = false;
}
});
});
});
</script>
Any help is appreciated.