I am currently creating a donation form that uses stages. To go from step to step, I use 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. The step after that (id = "step4") is for distribution. I want to skip this step and set the corresponding input value to 100 if the user selects only one checkbox. To catch, I donβt know how to start an array of flags (I suppose to use [name = list-item]) and I find that only one is selected, determine which one, and then skip the next step and set the corresponding distribution field to 100 What will be an effective way to do this?
Flags 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 distribution 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 all currently used JavaScript code: http://pastebin.com/P0YVRuqY
Resources I use:
- Php
- jQuery 1.8.3
- Twitter bootstrap
Thank you all for your time and help.
source share