So I have a function that validates form inputs and I noticed I had many questions so I wanted to automate it instead of typing it manually. So I created a for loop that goes from 1 to 25 and it works. But I want to add the i to 'q' so I won't have to type 'q1', 'q2', 'q3'... But I just can't add them together.
Here's my code:
$(function () {
for (var i = 1; i <= 25; i++) {
console.log(i);
$('#form_validation').validate({
rules: {
'checkbox': {
required: true
},
'q' + i: {
required: true
}
},
highlight: function (input) {
$(input).parents('.form-line').addClass('error');
},
unhighlight: function (input) {
$(input).parents('.form-line').removeClass('error');
},
errorPlacement: function (error, element) {
$(element).parents('.form-group').append(error);
}
});
}
});
So I don't really know how and I hope you could help me.