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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:41:24+00:00 2026-06-11T13:41:24+00:00

I have a dropdown and I want to make different tables appear below it,

  • 0

I have a dropdown and I want to make different tables appear below it, according to the selected option.

I’ve already seen it here:
Javascript – onchange within <option>

I was able to replicate that, but I really don’t know how to add more options/tables.

Can someone help? This is the code so far:

<html>
<head>
<script type="text/javascript">
window.onload = function() {
    var eSelect = document.getElementById('transfer_reason');
    var optOtherReason = document.getElementById('otherdetail');
     eSelect.onchange = function() {
        if(eSelect.value === "other") {
            optOtherReason.style.display = 'block';
            } else {
            optOtherReason.style.display = 'none';
        }
    }
    var optOtherReason = document.getElementById('other2');
     eSelect.onchange = function() {
        if(eSelect.value === "z") {
            optOtherReason.style.display = 'block';
            } else {
            optOtherReason.style.display = 'none';
        }
    }
}
</script>
</head>
<body>
<select id="transfer_reason" name="transfer_reason">
<option value="">Motivo</option>
    <option value="x">Reason 1</option>
    <option value="y">Reason 2</option>
    <option value="z">Reason 3</option>
    <option value="other">Other Reason</option>
</select>
<br>
<table border="1" id="otherdetail" style="display: none;">
<tr>
<th>Versão 11</th><th>Versão 12</th><th>Justificativas</th>
</tr>
<tr>
<td> 1</td><td>Angelina</td><td>Delhi</td>
</tr>
</table>

<table border="1" id="other2" style="display: none;">
<tr>
<th>Versão 11</th><th>Versão 12</th><th>Justificativas</th>
</tr>
<tr>
<td> 1</td><td>Galeno</td><td>Delhi</td>
</tr>
</table>
</body>
</html>

As it is now, only the table with id=”other2″ is loading correctly, while the other table is not.

  • 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-11T13:41:24+00:00Added an answer on June 11, 2026 at 1:41 pm

    There’s a better way than what exists in the example. If you use the table ID values in your drop-down the whole thing gets easier.

    <script type="text/javascript">
        window.onload = function() {
        var eSelect = document.getElementById('transfer_reason');
        var selVal;
        hideTables();
        eSelect.onchange = function() {
            hideTables();    
             selVal = eSelect[eSelect.selectedIndex].value;
            document.getElementById(selVal).style.display = "block";
        }
    
    }
    
    function hideTables() {
         var tables = document.getElementsByTagName("table");
        for(var x=0;x<tables.length;x++) {
            tables[x].style.display = "none";
        }
    }    
     </script>
    

    HTML:

      <select id="transfer_reason" name="transfer_reason">
            <option value="">Motivo</option>
            <option value="Table1">Reason 1</option>
            <option value="Table2">Reason 2</option>
            <option value="Table3">Reason 3</option>
            <option value="Table4">Other Reason</option>
    </select>
    
    <table id="Table1"><tr><td>#1#</td></tr></table>
    
    <table id="Table2"><tr><td>#2#</td></tr></table> 
    
    ... etc ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's my scenario: I have a drop down menu, with different values. When option
I want to make a dropdown menu, so I have a horizontal navigation with
I have a simple dropdown and want to get the specific value of an
Hi I have two dropdown menus: priceMaximum and mortgageMaximum I want it so if
I have a CSS dropdown menu that is functioning how I want it to
I want to have a drop down box that has a list of different
I have a drop down list and I want the selected value to put
I have dropdown menu below where it retrieves the possible modules id's and their
I have seen several sites where there is a form, starting with a dropdown
I want to make a selectOneMenu dropdown so I can select a status 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.