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 731257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:00:21+00:00 2026-05-14T07:00:21+00:00

I am working on a search box that displays different options based on a

  • 0

I am working on a search box that displays different options based on a users selection via dropdown box. Basically I need a really clean, light-weight method for switching out different divs without reloading the page. Im new to JS, but I know enough that there should be some really simple way of setting the display property using JS – Im just not totally sure how to go about it. Any help would be really appreciated, 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-14T07:00:21+00:00Added an answer on May 14, 2026 at 7:00 am

    Not using jQuery, here’s a little something that can do it. Real basic DOM stuff, but anyway…
    It is commented to death, but in general you give it a container id (in which your elements to show/hide are), and then some hide-all-then-show-one-of-them is done in the select element’s onchange. The way to retrieve element to show is basename+suffix (and the suffix is the value of the select’s option for a corresponding element).

    Here:

    <body>
    
    <select id="mySelect" onchange="npup.doSelect(this);">
        <option value="">Npup says 'select'</option>
        <!-- the option values are suffixes for the elements to show -->
        <option value="0">zero</option>
        <option value="1">one</option>
        <option value="2">two</option>
    </select>
    <!-- container for any elements that are to be in the game -->
    <div id="mySpecialElements">
        <!--  these have ids that end with and index  for easy retrieval in "findeElement" function  below-->
        <div id="npup0" class="hidden">div 0</div>
        <div id="npup1" class="hidden">div 1</div>
        <div id="npup2" class="hidden">div 2</div>
    </div>
    
    <script type="text/javascript">
    
    window.npup = (function (containerId, baseId) {
        // save the container of your special element
        var elementsContainer = document.getElementById(containerId);
        function doSelect(select) {
            // get value of select
            var value = select.value;
            // find element based on the value of the select
            var selected = findElement(value);
            if (!selected) {return;} // didn't find the element, bail
            // do hiding/showing of elements
            hideAll(elementsContainer);
            showElement(selected);
        }
        // retrieve some element based on the value submitted
        function findElement(value) {
            return document.getElementById(baseId+value);
        }
        // hide all element nodes within some parent element
        function hideAll(parent) {
            var children = parent.childNodes, child;
            // loop all the parent's children
            for (var idx=0, len = children.length; idx<len; ++idx) {
                child = children.item(idx);
                // if element node (not comment- or textnode)
                if (child.nodeType===1) {
                    // hide it
                    child.style.display = 'none';
                }
            }
        }
        // display a certain element
        function showElement(element) {
            element.style.display = '';
        }
        // hide all on page load (might want some extra logic here)
        hideAll(elementsContainer);
    
        // export api to use from select element's onchange or so
        return {
            doSelect: doSelect
        };
    })('mySpecialElements', 'npup'); // give the routine a container id of your special elements, and the base id of those elements
    </script>
    </body>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working on a search box for my site that will hopefully use
I am working on a search application that uses a form with 16 filter
id like to have an input box that a user can enter a search
I'm working on the search box for an events website. I've been recording the
I have a dropdown box that I construct with PHP. Here is the code:
I am having a search page with one dropdown list box, one button and
I'm working on a python plugin for Google Quick Search Box, and it's doing
I have a script for OS X 10.5 that focuses the Search box in
I am working on a Google Custom Search implementation that uses the option to
I have spatial search working well with SOLR 3.2 Example : ?q=*&fq={!geofilt pt=48.86761919303129,2.3527903735351856 sfield=coordinates

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.