Reputation: 2133
I have an input field ( source languages ) which i want when i click on one of the source languages, the target language with the same text is disabled
I done that so far but it keep disable the target languages when i click the source language
what i want to reset that every time .. not to make always listen to event
here is the demo http://jsfiddle.net/ezNxU/
// change the target language according to the source language
$('#source').change(function () {
var option_source = $('select#source option:selected').text();
$('select#target option').each(function () {
if ($(this).text() == option_source) $(this).prop("disabled", true);
console.log($(this).text());
});
});
Upvotes: 1
Views: 297
Reputation: 318332
To reset the disabled property, apply it on all the options, and use a function call to set it to true / false
$('#source').on('change', function() {
var self = this;
$('#target option').prop('disabled', function() {
return this.value == self.value;
});
});
Upvotes: 2
Reputation: 36551
just remove disable properties on change event...that will remove disable form all option and later yourcode will add it...
try this
$('#source').change(function () {
$('select#target option').prop("disabled", false); //<-- add this line
.....
Upvotes: 0
Reputation: 6306
use this to clear all
$('select#target option').prop("disabled",false);
so for your code : Fiddle
$('#source').change(function () {
var option_source = $('select#source option:selected').text();
$('select#target option').prop("disabled",false);
$('select#target option').each(function () {
if ($(this).text() == option_source) $(this).prop("disabled", true);
console.log($(this).text());
});
});
Upvotes: 0
Reputation: 11302
Try this:
$('#source').change(function () {
var option_source = $('select#source option:selected').text();
$('select#target option').each(function () {
$(this).prop("disabled", ($(this).text() == option_source));
});
});
Upvotes: 1