Search code examples
javascriptjqueryif-statementenable-if

how to enable search btn when all 3 inputs have value?


I have first, last inputs and country select, I have disabled search btn by default, how do I enable the search btn when all 3 inputs have value in them otherwise, disable the search btn? I have tried to use "and" in js, which is "&&", but it didn't work. Any help will be appreciated.

[jsfiddle][1]

[1]: http://jsfiddle.net/x9syr1v1/3/

Solution

  • See http://jsfiddle.net/x9syr1v1/4/

    Use change function otherwise you'll have tyo foucs out of drop down and use text() for the inputs:

    $('.first, .last, .country').change(function () {
        if ($('.first').text() == "" && $('.last').text() == "" 
            && $('.country').val() == "") {
            $('.search').attr('disabled','disabled');
        } else {
            $('.search').removeAttr('disabled');
        }
    });