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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:38:57+00:00 2026-06-02T07:38:57+00:00

I have a select box and want to show a help text in a

  • 0

I have a select box and want to show a help text in a hidden div when you click on an option:

<select  onchange="optionCheck()" multiple="multiple" name="test" id="options" size="15" class="form-select">
    <option value="1">option 1</option>
    <option value="2">option 2</option>
</select>

<div id="help1" style=visibility:hidden>help text 1</div>
<div id="help2" style=visibility:hidden>help text 2</div>

<script type="text/javascript">
    function optionCheck(){
        var option = document.getElementById("options").value;
        if(option == "1"){
            document.getElementById("help1").style.visibility ="visible";
            document.getElementById("help2").style.visibility ="hidden";
        }
        if(option == "2"){
            document.getElementById("help2").style.visibility ="visible";
            document.getElementById("help1").style.visibility ="hidden";
        }
    }
</script>

How can I create a simple loop so I don’t have to write “if” statements for each option?

 document.getElementById(option).style.visibility ="visible";

isn’t working – javascript and me don’t get along well 😉

Also, is there a simple way to hide all other divs when an option is selected?

  • 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-06-02T07:38:58+00:00Added an answer on June 2, 2026 at 7:38 am

    Here’s how I’d do it:

    First, I’m pretty lazy, and I don’t want to type style=”visibility: hidden;” on each of those divs. It’s easier to hide all of them at once with CSS:

    HTML:

    <select  onchange="optionCheck()" multiple="multiple" name="test" id="options" size="15" class="form-select">
      <option value="1">option 1</option>
      <option value="2">option 2</option>
    </select>
    
    <div id="help-wrapper">
      <div id="help1">help text 1</div>
      <div id="help2">help text 2</div>
    </div>
    

    CSS:

    #help-wrapper div {
      visibility: hidden;
    }
    
    /* It's better to use a class to highlight the selection,
       in case you feel like adding more styles later (like a border or something).
     */
    .current-help {
      visibility: visible;
    }
    

    Now we can work on making that Javascript a little more generic:

    function optionCheck()
    {
      var i;
      var optionIndex = document.getElementById("options").value;
    
      var helpWrapper = document.getElementById("help-wrapper");
      var helpDivs = helpWrapper.getElementsByTagName("div");
    
      // Loop through all the help divs.
      for (i=0; i<helpDivs.length; i++) {
        // Parse out the numeric portion of this help div's id.
        var helpIndex = helpDivs[i].substring[4];
    
        // If we found our div, highlight it.
        if (helpIndex === optionIndex) {
          helpDivs[i].className = "current-help";
        }
        // Otherwise, we should make sure it's hidden,
        // in case it was the previous selection.
        else {
          helpDivs[i].className = "";
        } 
      }
    }
    

    And that should do the trick!

    If you have any questions about the code above, I’d be happy to answer them.

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

Sidebar

Related Questions

I want the user to click the select box and when have selected any
I have a multiple select box which appears when I click the link 'Share'.
I have the following dropdown list box: <select name=DDLConditional1 size=1> <option selected=selected>is equal to</option>
I have this code that Show/Hide a text box if I select a category
I have a multi-select list box. I want to be able to select a
I want to have on my site a single select box that will then
I have a select box that gets generated dynamically. I want to allow users
I have a select box that gets cloned. I want to remove the user's
I want to show some children of div#options based on multiple values of the
I have a div which hides a select box. When a user clicks on

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.