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

  • SEARCH
  • Home
  • 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 6066069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:27:40+00:00 2026-05-23T09:27:40+00:00

Let me set up the situation: I have a form. This form has several

  • 0

Let me set up the situation:

I have a form. This form has several fields which are dependent upon a single drop-down, lets call it Art Kind. Based on the value of this Art Kind, several other fields are to be hidden/shown. Multiple values within this Art Kind dropdown can trigger the same set of fields being shown. For example.

User selects "Awesome", or "Cool", from the Art Kind dropdown:
     - URL and Name fields are shown
User selects "Rainbow", or "Double Rainbow", from the Art Kind dropdown:
    - URL and Name fields are hidden
    - Color and Size fields are shown

I think you get the idea.

I’m trying to come up with a better solution than something like this:

if (selected == "Awesome" || selected == "Cool")
{
    url.show();
    name.show();
}

Because there are a ton of fields, and a ton of different options that need be shown/hidden depending on selection. I’ve dabbled in an array, but I’m lost on how to get what I need accomplished.

I was thinking about storing the options in a multidimensional array, or an object, something like:

var values = [
     ['Awesome', 'Cool'], ['url', 'name']
]

But I’m not sure how to implement such a thing.

Any ideas? I’m open to answers that involve jQuery for simplification, but I’d rather keep other libraries out of it.

  • 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-23T09:27:40+00:00Added an answer on May 23, 2026 at 9:27 am

    A similar idea to @Pointy’s, somewhat different execution.

    function hideAllFormElements()
    {
        // snip...
    }
    
    function showElements(ids)
    {
        for (var i=0; i<ids.length; i++)
        {
            document.getElementById(ids[i]).style.display = 'none';
        }
    }
    
    var mapping = {
        Awesome: ['url', 'name'],
        Cool: ['url', 'name'],
        Rainbow: ['color', 'size'],
        'Double Rainbow': ['color', 'size']
    };
    
    // later...
    hideAllFormElements();
    showElements(mapping[selected]);
    

    Edit

    Because jQuery is the bee’s knees, instead of separate hide/show functions this will suffice, given just var mapping = {...} as above:

    $('#mySelect').change(function ()
    {
        var selected = $(this).val();
        
        $('#myForm :input').hide();
        $.each(mapping[selected], function ()
        {
            $('#' + this).show();
        });
    
        // or if you want to get really fancy,
        $($.map(mapping[selected], function ()
        {
            return '#' + this;
        }).get().join(', ')).show();
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

let's say I have this set of HTML-markup and CSS #CSS .inputhelp_text { background:
Here's my situation. I have a web root and several subdirectories, let's say: /var/www
I have a difficult situation, let me put it this way, I want the
Let me first describe my situation. I have a list of Hex values, which
Firstly, let me set out what I'd like to do. Assume I have three
Let say I have to parse a hierarchical set of tags <tag> <subtag1 attr1=value1
Here is my current situation: I have two tm structs, both set to the
I have a situation where I have a single activemq broker with 2 queues,
I'm facing a situation where I have dependent objects and I would like to
Let's say I have 2 instance of a class called 'Animal'. Animal has 3

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.