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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:17:50+00:00 2026-05-27T18:17:50+00:00

This is how far I got: <head> <script type=text/javascript> function showonlyone(thechosenone) { var article

  • 0

This is how far I got:

<head>
<script type="text/javascript">
function showonlyone(thechosenone) {
    var article = document.getElementsByTagName("div");
    for(var x=0; x<article.length; x++) {
        name = article[x].getAttribute("name");
        if (name == 'article') {
            if (article[x].id == thechosenone) {
                article[x].style.display = 'block';
            }
            else {
                article[x].style.display = 'none';
            }
        }
    }
}
</script>
</head>
<form>
<select>
<option SELECTED>Choose one</option>
<option value="javascript:showonlyone(id1)">First</option> <!-- That's probably wrong -->
<option value="javascript:showonlyone(id2)">Second</option>
</select>
</form>
<div name="article" id="id1" style="display:none;">
First one selected
</div>
<div name="article" id="id2" style="display:none;">
Second one selected
</div>

Here is what it should do:

  • Create a dropdownlist (with 3 Values)

  • If you click on “First” it should only show the of the content of <div id="id1">

  • If you click on “Second” it should only show the of the content of <div id="id2">

I know that this can’t work like this. But I do not know how I can get this working.
There might be a easier way than this javascript function but it has to be this way.

Thank you for your help

  • 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-27T18:17:51+00:00Added an answer on May 27, 2026 at 6:17 pm

    Use a onchange event handler instead:

    • Update your <select> to <select onchange="showonlyone(this)">.
    • Change your <option> values to only the IDs – not JavaScript calls.
    • Update your JavaScript to accept the HTMLSelectElement (which will be passed-in by the this, above). (Yes, you were correct here.)
    • From the chosen HTMLSelectElement, ask it for its value.

    Here is a fixed, working version: http://jsfiddle.net/YRF6u/

    Also included here:

    <head>
      <script type="text/javascript">
        function showonlyone(selector) {
          var thechosenone = selector.value;
          var article = document.getElementsByTagName("div");
          for(var x=0; x<article.length; x++) {
            name = article[x].getAttribute("name");
            if (name == 'article') {
              if (article[x].id == thechosenone) {
                article[x].style.display = 'block';
              }else{
                article[x].style.display = 'none';
              }
            }
          }
        }
      </script>
    </head>
    <form>
      <select onchange="showonlyone(this)">
        <option SELECTED>Choose one</option>
        <option value="id1">First</option>
        <option value="id2">Second</option>
      </select>
    </form>
    <div name="article" id="id1" style="display:none;">
      First one selected
    </div>
    <div name="article" id="id2" style="display:none;">
      Second one selected
    </div>
    

    I would not consider this production-ready code, but it should be sufficient enough to solve your current round of questions.

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

Sidebar

Related Questions

This is what I got so far, and it's not working at all :(
I want to append a script tag which executes one line of JavaScript to
I want to create a pagination script using jquery UI's slider widget. So far
I'm having a rough time wrapping my head around this. I have an HTML
Today I got my book Head First Design Patterns in the mail. Pretty interesting
I'm in a little over my head here with OOP in actionscript. I've got
I'm fairly new to jquery and so far i have got my code to
I'm trying to populate the pull down menu. so far ive got: <%@ Page
I got to deep in this problem and can not see the forest out
so...i've been banging my head on this for a bit. I'm getting the most

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.