1

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());
});

});
0

4 Answers 4

2

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;
    });
});

FIDDLE

Sign up to request clarification or add additional context in comments.

Comments

1

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));
    });
});

DEMO

Comments

0

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());
            });
        });

Comments

0

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
   .....

fiddle here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.