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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:10:22+00:00 2026-06-13T03:10:22+00:00

I have a selectbox with some options. Each option should, if selected, show a

  • 0

I have a selectbox with some options.
Each option should, if selected, show a separate div.

Of course I could do it for every optionname/value like this:

HTML:

<form class="floatleft">
      <select size="1" id="stadtauswahl" name="Standortauswahl">
        <option value="" style="color: #666;">&nbsp;&nbsp;&nbsp;Bitte wählen Sie&nbsp;&nbsp;&nbsp;</option>
        <option value="/kontakt/hauptsitz/">&nbsp;&nbsp;&nbsp;Wiesbaden</option>
        <option value="/kontakt/berlin/">&nbsp;&nbsp;&nbsp;Berlin</option>
        <option value="/kontakt/bad-harzburg/">&nbsp;&nbsp;&nbsp;Bad Harzburg</option>
        <option value="/kontakt/koeln/">&nbsp;&nbsp;&nbsp;Köln</option>
        <option value="/kontakt/hamburg/">&nbsp;&nbsp;&nbsp;Hamburg</option>
        <option value="/kontakt/muenchen/">&nbsp;&nbsp;&nbsp;München</option>
        <option value="/kontakt/stuttgart/">&nbsp;&nbsp;&nbsp;Stuttgart</option>
      </select>
    </form>

jQuery:

$(document).ready( function() {
  $('#stadtauswahl').bind('change', function (e) { 
    if( $('#stadtauswahl').val() == '/kontakt/hauptsitz/') {
      $('#wiesbaden').slideToggle();
    }
    else{
      $('#wiesbaden').slideUp();
    }         
  });
});

But I want jQuery to read out the name and then select the div of the same name to show.

  • 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-13T03:10:23+00:00Added an answer on June 13, 2026 at 3:10 am

    Try this code instead…

    $(document).ready( function() {
        $('#stadtauswahl').bind('change', function (e) { 
            $(this).find("option").each(function() {
                var text = $(this).text().toLowerCase().split(" ").join("").trim();
                console.log("'" + text + "'");
                if ($(this).is(":selected")) {
                    $('#' + text).slideDown();
                } else {
                    $('#' + text).slideUp();
                }
            });
        });
    });​
    

    It will look for a div for each of the options (with all spaces removed from the text) and perform a slideUp() for all non-selected ones, and a slideDown() for the selected one.

    Note

    Ideally, you would give each of the divs to show/hide a class that you can use to hide them all and then it becomes easier to just show the one relevant one. Also, unless there’s a reason for having a path as the select value it would be better to use the div IDs as the values, so you don’t have to rely on the text not having invalid characters in it (for IDs).

    It may make more sense to have an array of objects that have a url parameter and a text parameter, and you hold the index of each of them in the select options. This would mean you could simply look at the value of the selected option and use it to get all the associated info from the array.

    Just options and thoughts – the above script will do what you ask though 🙂

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

Sidebar

Related Questions

I have a selectbox with several options - each of these option values correspond
I have a selectbox with three options. When a user selects one of the
i am having an add to basket problem.Some products have options like color/size. I
I have written some javascript code that's supposed to put options into a select
In a form I have a select box with several options, each representing a
I have some divs, each with a radio button and a drop-down box. What
i have one form which have some input box and some select box. i
We have a custom JSF component that renders some buttons and a select box
I have a selection for some items using a spinner widget. At the moment
I have a jsp where some radio buttons and textboxes depend on dropdown selection.

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.