My current project involves creating a dynamic form where the number of fields displayed changes based on the user's selection from a dropdown menu. This means that depending on what option they choose, anywhere from 2 to 20 different fields may be shown.
I want to submit only the visible form fields related to the user selection in the URL parameter. Currently, all values are being submitted in the URL string.
Scenario 1:
If the user selects "A" from the drop down, we display input fields for first name and last name with the URL parameters: ?fname=fname&lname=lname
Scenario 2:
If the user selects "B" from the drop down, we show first name, last name, and address fields with the URL parameters: ?fname=fname&lname=lname&addres=address
Scenario 3:
For the selection of "Z," we display various fields such as first name, last name, address, zip code, age, SSN, child name, sex, cell phone, home phone, and office phone along with corresponding URL parameters.
My main question is how can I dynamically build a URL query string based on the user's selection from the dropdown menu? How can this process keep track of 20 to 30 different selections, each requiring different form fields?
What would be the best approach for this task? Would using JSON provide the necessary information for assembling the URL query string?
Are there any examples or resources available to guide me through this process?