I need to dynamically change 2 select fields by using a little math and php (a JS solution would be fine too.).
Example: I'm booking a trip...
- I can have 8 travelers total.
- 1 traveler needs to be an adult
- The rest can be 7 kids if needed
Adult select field:
@for($adults = 1; $adults<=8; $adults++)
<option value="{{ $adults }}">{{ $adults }}</option>
@endfor
Based on the Adults number value, this needs to reflect how many Kid spots are left.
Kids select field:
@for($kids = 0; $kids <= 8 - $step->adults; $kids++)
<option value="{{ $kids }}">{{ $kids }}</option>
@endfor
So some quick examples:
- 1 adult = 0-7 kids
- 2 adults = 0-6 kids
- 3 adults = 0-5 kids
- 4 adults = 0-4 kids etc..
This is a multi-step form and I'm currently storing everything in a session/cookie. As I have it now, the Kids logic only works if I hit the continue button. (Not ideal)
How can I get the Kids to update immediately based on the Adults value before I continue to the next form.
I'm currently using Laravel / PHP, but a JS solution would be acceptable if needed.
I would appreciate any help.