javascript - Check if all inputs have value of zero with JS or jQuery -


i'm trying check if inputs (.producttextinput) have value of zero.

if 0 execute alert, if zero.

i have been able check first , individually, not together.

html

<div class="container">     <div class="listquantity">         <input type="text" class="producttextinput" name="addtocart_amount" value="0">     </div>     <div class="listquantity">         <input type="text" class="producttextinput" name="addtocart_amount" value="0">     </div>     <div class="listquantity">         <input type="text" class="producttextinput" name="addtocart_amount" value="0">     </div> </div> 

script

$('.producttextinput').each(function() {     if ($(this).val() <= 1){         alert("must choose @ least 1 product");     } else {         //     } }); 

you can use filter this:

if ($('.producttextinput').filter(function() {         return parseint(this.value, 10) !== 0;     }).length === 0) {     // have 0 } else {     // @ least 1 has non-zero value } 

Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -