html - JQuery Loop Through Elements and Return False If All Are Empty -
how loop through elements of class name , return false if every element has no value/is null?
i know increment int, or add string, or test if every field empty after loop finishes seems unsustainable, not mention terrible way it.
currently have js file:
function verifypositions() { $(".position").each(function () { if ($(this).val() == "") { } }); }
and html:
<div class="spacing"> <a class="applicationlabel">position(s) interested in:</a><br> <input class="position" name="position[]" value="project manager" type="checkbox" /> project manager<br> <input class="position" name="position[]" value="content developer" type="checkbox" /> content developer<br> <input class="position" name="position[]" value="graphic designer" type="checkbox" /> graphic designer<br> <input class="position" name="position[]" value="digital media creator & storyteller" type="checkbox" /> digital media creator & storyteller<br> <input class="position" name="position[]" value="programmer" type="checkbox" /> programmer<br> <input class="position" name="position[]" value="server engineer/technician" type="checkbox" /> server engineer/technician<br> <input class="position" name="position[]" value="user experience designer" type="checkbox" /> user experience designer<br> </div>
edit: fixed it
function verifypositions() { var flag = false; $(".position").each(function () { if ($(this).prop('checked')) { flag = true; } }); if (!flag) { return false; } else { return true; } }
function verifypositions() { $(".position").each(function () { if ($(this).val() !== "") { return true; } }); return false; }
Comments
Post a Comment