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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:59:49+00:00 2026-05-20T17:59:49+00:00

I have 2 drop downs and I’m using the switch to populate the second

  • 0

I have 2 drop downs and I’m using the switch to populate the second after something has been selected in the first. It’s mostly just an experiment because the jquery thing i had doing it before seemed really slow. If anyone has a better, faster way of doing this, I’m all ears. But I still want an answer to this because it’s just irritating me now.

The first drop downs onchange="chngprog(this)" calls this function

function chngprog(facility)
{
    if(facility.id == 'facilityview'){
        var select = document.getElementById('programview');
    } else {
        var select = document.getElementById('program');
    }
    var testid = facility.value;
    switch(testid){
        <?php global $__CMS_CONN__;
        $sqlqry = "SELECT * FROM facility_db";
        $stmt = $__CMS_CONN__->prepare($sqlqry);
        $stmt->execute(); 
        $listfacility = $stmt->fetchAll(PDO::FETCH_ASSOC);
        foreach($listfacility as $case)
        {
            echo "case ".$case['id'].":\n";
            echo "select.options = '';";
            $boom = explode(";", $case['programs']);
            foreach($boom as $program)
            {
                echo "select.options[select.options.length] = new Option('$program', '$program');\n";
            }
            echo "break;\n";
        }
        ?>
    }

}

The php creates all the cases from the database, as there are 50+, probably not helping the speed factor.

The if statement at the top is to determine which set of drop downs it’s looking at, as there are 2 sets that do the same thing, but for different purposes.

The problem is getting the switch to hit a case. I’ve put alerts around to see what happens, and all the values are right, but it never hits a case unless is specify the number. If i put switch(20) it hits case 20 and adds the options to the second drop down just as it should.

So why isn’t the switch evaluating the variable I put in?

  • 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-20T17:59:50+00:00Added an answer on May 20, 2026 at 5:59 pm

    Is facility.value a string? Try

    var testid = parseInt(facility.value, 10);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 2 drop downs example country and province. The country can be selected
I have a form that has multiple select drop downs. i.e. Item 1: <select
Something seems to have happened to my development environment. All of the drop downs
I have a form currently has 2 drop downs. Selecting an option from the
I have 2 drop downs. In the first one you choose a model, in
I have n drop-downs like this: <select id=select1> <option>1</option> <option>2</option> <option>3</option> </select> <select id=select2>
I have a drop down list that has options that need to be passed
I have three drop downs in mypage.php: <select name='vehicle'> <option value=''>Select</option> <option value='bus'>Bus</option> <option
I have two sets of drop downs for start date and end date. Each
Say I have two drop downs which are populated when the my jsp loads

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.