I have a form with the following inputs:
<input type="text" name="products[1][rrp]" class="rrp">
<input type="text" name="products[1][sale_price]" class="sale-price">
<input type="text" name="products[1][beg_inv]" class="beg-inv">
<input type="text" name="products[1][end-inv]" class="rrp">
<input type="text" name="products[1][sold]" class="sale-price">
<input type="text" name="products[1][sampled]" class="beg-inv">
<input type="text" name="products[2][rrp]" class="rrp">
<input type="text" name="products[2][sale_price]" class="sale-price">
<input type="text" name="products[2][beg_inv]" class="beg-inv">
<input type="text" name="products[2][end-inv]" class="rrp">
<input type="text" name="products[2][sold]" class="sale-price">
<input type="text" name="products[2][sampled]" class="beg-inv">
When the form submits, I want to make sure the user has entered every one of these inputs. Here is the jQuery I’m using:
$("form#answerReport").submit(function(){
if($(".rrp").val()=='' || $(".sale-price").val()=='' || $(".beg-inv").val()=='' || $(".end-inv").val()=='' || $(".sold").val()=='' || $(".sampled").val()==''){
$(".error.hide").text("Please fill in the product information").show();
return false;
}
});
But the form is still submitted if there’s input values for products[1] but not input values for products[2]. Does anybody know where I’m going wrong?
you are missing the
$instead ofdo
your code should be like
here is the fiddle http://jsfiddle.net/3nigma/NewsM/
Update
im not sure about your scenario but before the submit you should validate the fields if you have the following html
on
clickvalidate all the input fields of typetexthere is the fiddle http://jsfiddle.net/3nigma/NewsM/1/