How do I loop through dynamic variables with jQuery?
I have a form where people can sign up for summer camps with optional lunch or after-camp babysitting, but they have to select a camp in order to be able to select the lunch/babysitting that goes with it. The form is generated from a database with the following code (basically):
I figured the best thing to do would be to set both the lunch and babysitting checkboxes to "disabled" to start then, when a Camp Name checkbox was checked, remove the disabled attribute for the corresponding lunch/babysitting boxes with something like this:
function toggleOptions() { if ($('#attending#camp_ID#').is(':checked')) { $('#lunch#camp_ID#').removeAttr('disabled'); $('#babysitting#camp_ID#').removeAttr('disabled'); } else { $('#lunch#camp_ID#').attr('disabled', true); $('#babysitting#camp_ID#').attr('disabled', true); } }
Open in new window
Then, add the following to your document.ready handler:
Open in new window