I currently have a page that allows a user to enter different types of database entries via a select("questions" for a survey), i.e. Multiple Choice, Text, Drop-down, etc. Each one atleast contains a textarea and 2 input type="text"s.
Right now this is done by having 4 divs in the HTML, 3 of which are hidden via CSS ("display:none"). Then a JS action is hit on the select change, which uses a switch statement to hide and unhide all the divs correctly. Form.onsubmit deletes all the divs except the currently selected one, as they all use the same names for their inputs.
Obviously this is incredibly inefficient and ugly. I think the correct way would be to create the elements using JS, something I suck at, and then when the user changes the select, remove the child div from the form and add the desired form div. However, I don't know how to do this.
I would greatly appreciate it if someone could show me how to go about my suggestion, or show how to do it better.
Thanks.