1

Can't figure out how to check if at least one input is filled which means it is not empty and the value is greater than zero.

I can check it for empty value or zero but I want to check for both values.

Tried to put && after value!="" which didn't work.

$('#id_calculator_form').find(':input[value!=""]').not('#id_postcode'){

}

1 Answer 1

3

You can filter based on multiple values

var els = $('#id_calculator_form :input').filter('[value!=""], [value!="0"]');

if (els.length > 0) {...

Note that selecting by value attribute, only works on elements with a set value attribute, if you want to filter based on inputted value, you should check the property instead

var els = $('#id_calculator_form :input').filter(function() {
    return this.value !== "" && this.value !== "0";
});

if (els.length > 0) {... // at least one input is not zero or empty
Sign up to request clarification or add additional context in comments.

3 Comments

I'm afraid this doesn't work for some reason. console.log($('#id_calculator_form :input').filter('[value!=""], [value!="0"]')) returns all inputs, even those which are increased to 2.
Try the second approach if you're checking this in an event handler ?
Thanks, yes it's on change any input handler. The second approach works.

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.