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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:35:12+00:00 2026-05-27T04:35:12+00:00

I have a slight problem with my dropdown function. What is suppose to happen

  • 0

I have a slight problem with my dropdown function. What is suppose to happen is that is if (optionDrop[0].value == “”) (this is “Please Select” option in dropdown menu which I put a comment in the function so you know where the problem is), then do not display the buttons A, B or C. This works when the page is opened as the pre-select value is “”, but when I click on the dropdown menu OR select the value “” again, then it displays buttons B and C and only does not display A. Buttons A, B and C are supposed to not be displayed. Why is it acting like this?

Below is function (I put a comment where the problem is)

        function getDropDown() {
var optionDrop = document.getElementsByName("optionDrop");
var na = document.getElementById("na");
var numberDrop = document.getElementsByName("numberDrop");
var answer = document.getElementsByName("answer");

if (optionDrop[0].value == "abc" || optionDrop[0].value == "abcd" || optionDrop[0].value == "abcde"){
numberDrop[0].style.display = "block";
na.style.display = "none";

                }

    // THIS IS THE PROBLEM

else if (optionDrop[0].value == "trueorfalse" || optionDrop[0].value == "yesorno"){         
numberDrop[0].style.display = "none";
na.style.display = "block";

}else if (optionDrop[0].value == ""){           
numberDrop[0].style.display = "none";
na.style.display = "none";
answer[0].style.display = "none";
answer[1].style.display = "none";
answer[2].style.display = "none";           
                            }         


if (optionDrop[0].value == "abc" && numberDrop[0].value == "1")
answer[0].style.display = "block";
answer[1].style.display = "block";
answer[2].style.display = "block";
                        }

Below is html of dropdown menus and buttons:

<form id="enter" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post" >
<table id="middleDetails" border="1">
<tr>
      <th colspan="2">
        Option and Answer
    </th>
</tr>
<tr>
    <td>Option Type:</td> 
    <td>
        <select name="optionDrop" onClick="getDropDown()">
<option value="">Please Select</option>
<option value="abc">ABC</option>
<option value="abcd">ABCD</option>
<option value="abcde">ABCDE</option>
<option value="trueorfalse">True or False</option>
<option value="yesorno">Yes or No</option>
</select>
    </td>
<tr>
<td colspan="2"></td>
<td>Number of Answers:</td>
<td>
<span id="na">N/A</span>
<select name="numberDrop" id="numberDropId" onClick="getDropDown()>
<option value=""></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</td>
</tr>
<tr>
<td colspan="2"></td>
<td>Answer</td>
<td>
<input class="answerBtns" name="answer" type="button" value="A" />
<input class="answerBtns" name="answer" type="button" value="B" />
<input class="answerBtns" name="answer" type="button" value="C" />
<input class="answerBtns" name="answer" type="button" value="D" />
<input class="answerBtns" name="answer" type="button" value="E" />
<input class="answerBtns" name="answer" type="button" value="True" />
<input class="answerBtns" name="answer" type="button" value="False" />
<input class="answerBtns" name="answer" type="button" value="Yes" />
<input class="answerBtns" name="answer" type="button" value="No" />
</td>
</tr>
</table>
</form> 

Below is CSS;

.answerBtns{
    display:none;
    }
  • 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-27T04:35:12+00:00Added an answer on May 27, 2026 at 4:35 am

    You are missing a set of braces for the if statement at the end of your javascript function:

    if (optionDrop[0].value == "abc" && numberDrop[0].value == "1")
    answer[0].style.display = "block";   // conditionally executed
    answer[1].style.display = "block";   // always executed
    answer[2].style.display = "block";   // always executed
    

    Therefore, the last two statements are always executed and the B and C buttons are always shown. You want to have something like this instead:

    if (optionDrop[0].value == "abc" && numberDrop[0].value == "1")
    {
      answer[0].style.display = "block";   // conditionally executed
      answer[1].style.display = "block";   // conditionally executed
      answer[2].style.display = "block";   // conditionally executed
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a slight problem with my application. What is suppose to happen is
am new here. i have a slight problem; PLease look at the following code
I've wrote this simple piece of code. And I have a slight problem with
I have a slight problem, I'm making a dropdown using the help from someone
I have this GWT code below which have some slight problem: It's either the
I have a slight problem with getting the options within the select tag. Some
I have a slight problem with this code: string[] sWords = {Word 1, Word2}
Hey all, have a slight problem here. In CakePHP I have a controller that
I'm having a slight problem. I have set my <input type=file> to onChange=this.form.submit() .
Slight problem i have been pondering on, i have a class that loads a

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.