简体   繁体   中英

Check 2 input fields and a select field for changing after they all have been filled

I have 2 input fields and a select box. When someone fills in all 3 fields there has to be some calculation. Everytime on of these fields change when they are all filled, the calculation should be fired again.

I achieved to do this with just the select box like this.

function showPrice() {
    calculate();
    $('#overview').removeClass('hidden');
}


$(".select").on('change', function()
    {
        showPrice();
    }
);

But how can I do this with 3 elements from different types?

Create a function that loops through all elements you want and returns true if all of them are filled.

This would be the basic code:

    function check(){
    var filled = true;
    $('input').each(function(inx,elem){
        if($(elem).val()=='')
            filled = false;
    });

    return filled;
}

Check a working example HERE

Note that I used text and file types, but that should do for any type.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM