I've recently built a funeral cost calculator tool for a client using Jquery Steps.
The tool's form is quite complex, as a number of steps depend on whether certain form options have been selected.
I managed to accommodate this myself by using the "insert" and "remove" methods triggered "onchange" of the radio buttons. When the user selects that a death has occurred, there are 7 steps. When a user selects that a death has not occurred, there are 5 steps (see images attached). (See below for some sample code)
No death occurred (screenshot)
The steps are inserted and removed at index 4. If a user toggles back and forth between the options, it will insert the 2, then remove the 2, insert the 2, then remove the 2, etc. I found this was simple enough.
Trouble came when further into the form I needed to apply a similar condition. However, I found that I couldn't specifically target an index to insert or remove at because I couldn't predict how many steps there were at this point (as it is based on the user's previous selection - see above).
My javascript knowledge is limited, so I'm at a loss. I know the logic needed to make it work, I just don't know how to implement it.
I want to know how I can use javascript/jquery to count the number of steps (in order to target the last step) and target the current step. Unless of course there's a simpler or better method that somebody can suggest.
I've been racking my brains over this, any help would be appreciated. Thank you!
<input type="radio" name="deathOccurred" rel="death-occured-yes" value="Yes" class="required" onclick="calculateTotal()" onchange="$('#estimator-form').steps('insert', 4, {
title: 'Clergy/Celebrant',
content: '<STEP HTML HERE>'
});
$('#estimator-form').steps('insert', 5, {
title: 'Other options',
content: '<STEP HTML HERE>'
/> Yes
<input type="radio" name="deathOccurred" rel="death-occured-no" value="No" checked onclick="calculateTotal()" onchange="$('#estimator-form').steps('remove', 5, {}); $('#estimator-form').steps('remove', 4, {});" /> No