I have a HTML structure like this:
<div class="input_div_0">
<input type="text" class="textbox input">
</div>
<div class="input_div_1">
<input type="text" class="textbox input">
</div>
<div class="input_div_2">
<input type="text" class="textbox input">
</div>
I want to write an expression that will return true if any of the input
s contain text
EDIT
Based on Dimitar's answer I've come up with this:
function checkInputs()
{
$('input.textbox').each(function () {
if ($(this).val() !== "") {
return true;
}
});
return false;
}
if (!checkInputs()) {
//Display message
}
However the false is returned every time.
Try utilizing Array.prototype.some
var res = Array.prototype.some.call(document.querySelectorAll("input")
, function(el, i) {
return el.value.length > 0
});
console.log(res);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="input_div_0">
<input type="text" class="textbox input">
</div>
<div class="input_div_1">
<input type="text" class="textbox input">
</div>
<div class="input_div_2">
<input type="text" class="textbox input" value="0">
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With