Hello, is there a way to iterate through a set of form names (box1, box2, box3, box4, box5) using the validate rules in jQuery? If not, what other method can be used to loop through each textbox for validation? Thanks much for any help.
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="http://jzaefferer.github.com/jquery-validation/jquery.validate.js"></script>
<script type="text/javascript">
jQuery.validator.setDefaults({
debug: true,
success: "valid"
});;
</script>
<script>
$(document).ready(function(){
$("#myform1").validate({
rules: {
box1: {
required: true,
range: [13, 23]
}
}
});
});
</script>
<script>
$(document).ready(function(){
$("#myform2").validate({
rules: {
var textBox=["box1","box2","box3","box4","box5"];
for ( $counter = 1; $counter <= textBox.length; $counter ++) {
return textBox;
}: {
required: true,
range: [13, 23]
}
}
});
});
</script>
</head>
<body>
<form id="myform1" method="post">
<label for="field">Required, minimum 13, maximum 23: </label>
<input type="text" name="box1" id="var1" value="" >
</form>
<br>
<form id="myform2" method="post">
<label for="field">Required, minimum 13, maximum 23: </label>
<input type="text" name="box1" id="var1" value="" >
<input type="text" name="box2" id="var1" value="" >
<input type="text" name="box3" id="var1" value="" >
<input type="text" name="box4" id="var1" value="" >
<input type="text" name="box5" id="var1" value="" >
</form>
</body>
</html>
Sorry, I could not separate the JavaScript and HTML in the fiddle and make them work. It might be because of the required jQuery plugin. So, I put the entire code in one area. This code contains one validation that works but it is the second validation (iterating through the set of textboxes) which I cannot make function. Thanks much for any help.