I’m currently creating a donation form that uses steps. To move from step to step, I am using jQuery (specifically the following function):
function showNextStep(currentStep) {
$("#step" + currentStep).slideToggle("slow", function () {
if (currentStep === 1) {
//figure out what kind of donation they are making
var chosenDonationType = $("[name=donationType]").val();
//show the apppropriate slide
switch (chosenDonationType) {
case "oneTimeGift":
currentStep += 1;
$("#makingAOneTimeGift").show();
$("#step" + currentStep).slideToggle("slow");
break;
case "recurringDonation":
currentStep += 1;
$("#makingARecurringGift").show();
$("#step" + currentStep).slideToggle("slow");
break;
//if somehow they changed it to something else, ignore them and return false.
default:
return false;
//break; not needed due to return
}//end switch
} else {
currentStep += 1;
$("#step" + currentStep).slideToggle("slow");
}
});
}
I have a list of funds that the user can donate to as well. The step after this (id=”step4″) is for allocations. I want to skip that step and set the corresponding input value to 100 if the user only selects one checkbox. Catch is, I don’t know how to run through the array of checkboxes (I’m assuming using [name=list-item]) and find that only one is selected, identify which one, and then skip the step next step and set the value to of the respective allocation box to 100. What would be a performance effective way to do this?
Checkboxes use the following style:
<label class="checkbox">
<input type="checkbox" id="showGoodMenGoodCitizensAllocation" name="list-items[]" value="Good_Men_Good_Citizens" />
Good Men, Good Citizens Scholarship
</label>
<label class="checkbox">
<input type="checkbox" id="showClassof2012Allocation" name="list-items[]" value="Class_Of_2012" />
Class of 2012 Scholarship <abbr title="In Honor Of">IHO</abbr> Mr. Jason M. Ferguson ’96
</label>
<label class="checkbox">
<input type="checkbox" id="showClassof2011Allocation" name="list-items[]" value="Class_Of_2011" />
Class of 2011 Scholarship <abbr title="In Honor Of">IHO</abbr> Ms. Anita Garland
</label>
The allocation inputs are as follows:
<div id="GoodMenGoodCitizensAllocation" class="input-append hiddenByDefault">
<input type="number" name="Good_Men_Good_Citizens-Allocation" min="0" max="100" value="0" />
<span class="add-on">% to the Good Men, Good Citizens Scholarship</span>
</div>
<div id="ClassOf2012Allocation" class="input-append hiddenByDefault">
<input type="number" name="Class_Of_2012-Allocation" min="0" max="100" value="0" />
<span class="add-on">% to the Class of 2012 Scholarship <abbr title="In Honor Of">IHO</abbr> Mr. Jason M. Ferguson ’96</span>
</div>
<div id="ClassOf2011Allocation" class="input-append hiddenByDefault">
<input type="number" name="Class_Of_2011-Allocation" min="0" max="100" value="0" />
<span class="add-on">% to the Class of 2011 Scholarship <abbr title="In Honor Of">IHO</abbr> Ms. Anita Garland</span>
</div>
For the full page code:
http://pastebin.com/yFv2day1
For the full javascript code currently used:
http://pastebin.com/P0YVRuqY
Resources I am using:
- PHP
- jQuery 1.8.3
- Twitter Bootstrap
Thank you all in advance for your time and assistance.
Try this snippet: