Check if atleast one field is not empty in PHP
is very equal to this question. This is just how to do it in javascript.
When you click on #submit it should check atleast one of these fields:
input[name=weight], input[name=size_1], input[name=size_2], input[name=size_3]
are filled, and not empty. If all of them are empty, it should alert(“Please fill one of the fields”)
Update: forgot to mention that if the fields are 0 it should not be counted as filled.
How can i do this? I tried copy over from php, but i get stuck on the foreach loop
You could do this very easily with the
filtermethod:What this does:
filtermethod: if you return true, the element will be kept; if you return false, it will be removed from the selection!!this.valueistrueif the value is a non-empty string and otherwise is falselengthproperty of the selection. If it is not0, at least one element has a non-empty value. If it is0, they are all empty.See:
filterlength