Reputation: 1180
I have a tag and within that div that I have multiple elements. Is there a way where I can check to see if any of those input elements were filled in ?
To add to it, the reason I am doing this is because I have a huge form divided into 4 tags which takes care of different section. I want to run validation for this section only when something is inputted by the user. Hope that makes sense!
Upvotes: 2
Views: 197
Reputation: 12132
Assuming you have something like this:
<div class="input_container">
<input name="something">
<input name="something">
<input name="something">
<input name="something">
</div>
<div class="input_container">
<input name="something">
<input name="something">
<input name="something">
<input name="something">
</div>
<div class="input_container">
<input name="something">
<input name="something">
<input name="something">
<input name="something">
</div>
you can use jquery like this:
$(".input_container").each(function () {
//iterates over each INPUT CONTAINER
$(this).children('input').each(function () {
//iterates over each INPUT element
if ($(this).val() === "") {
alert("Not filled in");
}
});
})
Upvotes: 1