Please consider the simple form with jQuery validation code below. Somehow I (still) go wrong with the syntax for the rules, as the validation does not work in this way (while I checked some sites on stackoverflow on this topic). How to describe the rule properly using arrays?
Please your help.
Code:
<form id="myForm" name="myForm" action="" method="post" autocomplete="on">
<label class="field2" for="productname[0]"> Product name 1 </label> <input id="productname[0]" type="text" name="productname[0]"> <br>
<label class="field2" for="productname[1]"> Product name 2 </label> <input id="productname[1]" type="text" name="productname[1]"> <br>
<input type="submit" name="submitForm" value="Submit Form">
<script src="js/jquery-1.10.1.min.js"></script>
<script src="js/jquery.validate.js"></script>
<script>
$(function() {
$("#myForm").validate({
rules: {
'productname[]': {
required:true,
minlength: 2,
maxlength: 30,
}
} //rules
}); //validate()
}); //function
</script>
</body>