I have a form with 8 select fields numbered 1 to 8. I have the code below working to show/hide the recurring div numbered 1 to 8 but can't figure out how to put it in a loop to prevent duplicate script. Should I use the for loop or each command for this? any help is appreciated. Below is an example of what currently works for the first 2 select boxes.
jQuery(function() {
id = 1;
jQuery('#leveltype' + id).change(function() {
if (jQuery(this).val() == "recurring") {
jQuery('#recurring' + id).show();
} else {
jQuery('#recurring' + id).hide();
}
});
});
jQuery(function() {
x = 2;
jQuery('#leveltype' + x).change(function() {
if (jQuery(this).val() == "recurring") {
jQuery('#recurring' + x).show();
} else {
jQuery('#recurring' + x).hide();
}
});
});