I have this HTML:
<fieldset style="display: block;" title="Producto" class="fstep" id="product-create-step-2">
<section>
<div class="p_name">
<input type="text" maxlength="50" required="required" name="product[name]" id="product_name">
</div>
<div class="p_description">
<textarea required="required" name="product[description]" id="product_description"></textarea>
</div>
<div class="p_age">
<input type="text" value="0" name="product[age_limit]" id="product_age_limit">
</div>
</section>
</fieldset>
And I'm trying to show a alert for each element with required="required"
with empty values so I made this:
$('#product-create-step-2 > input[required="required"]').each(function() {
if (!$.trim(this.value).length) {
alert($(this).prev('label').text() + ' can't be empty!!!');
valid = false;
}
});
If I leave #product_name
or #product_description
empty it never shows a alert and I can't find what I miss, any advice?