Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 543539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:33:42+00:00 2026-05-13T10:33:42+00:00

I currently have a page that allows a user to enter different types of

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T10:33:43+00:00Added an answer on May 13, 2026 at 10:33 am

    Actually your method doesn’t sound too bad at all. One of two things I would call into question would be the reasoning for naming them all the same thing – if they really represent the same data, why not actually use the same form elements for all 4 sections?

    The other thing I would want to improve is the need to remove anything from the DOM when the form submits. This not only adds complexity to your submission process, but it also prevents problems if the user hits the back button to try again.

    I would not create/destroy elements every time the value is changed — not only is this somewhat more inefficient, it is a pain to maintain, more susceptible to bugs, and will blow away any information the user has entered.

    I think there are two main options which could improve this for you:

    1) Keep the same fields

    If the 4 types really do have 3 common fields each, why don’t you have those in a section which never gets hidden, and have any only the information unique to each type in a special section which can be shown or hidden when the value of the SELECT element is changed.

    2) Disable the fields that are hidden

    Fields that are disabled are simply not sent to the server. Therefore, you can keep the same names on multiple elements, without having to delete them before submission, as long as you make sure only one is not disabled. I use a toggleDisabled method that will take an element and iterate over all children and all descendants recursively and disable or enable input/select/textarea elements. Then I can just pass in a single element and enable/disable all form elements. It would work perfectly for what you are trying to do – you would hide your DIV, then you would disable it. You would then show and enable the selected one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to have generalised email templates. Currently I have multiple email templates with
We manage a site for a medical charity. They have a number of links
I am using a 3rd-party rotator object, which is providing a smooth, random rotation
IE is giving me an undefined NAN when i try to view the calender...

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.