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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:38:42+00:00 2026-05-26T23:38:42+00:00

I have two drop down lists. Second one is populated based on value chosen

  • 0

I have two drop down lists.
Second one is populated based on value chosen in the first one. I’m using Double Combo Script Credit By JavaScript Kit to do that (I am very bad with javascript).
I use this to filter results from my Mysql database.
The problem is that when user applies filter i want him to see what he applied (when page refreshes or user goes to other page) – those values should be seen as selected in both drop down lists. I can’t figure out where i should place an event or something else.

I’m holding subcategory values from the second drop down list in php session :

if (isset($_SESSION['subcat']) && !isset($_GET['subcat'])){
$color= $_SESSION['subcat'];
}
elseif (!isset($_SESSION['subcat']) && isset($_GET['subcat']))
{
    $_SESSION['subcat'] = mysql_real_escape_string($_GET['subcat']);
    $color= $_SESSION['subcat'];
    }
    elseif (isset($_SESSION['subcat']) && isset($_GET['subcat'])){
        unset($_SESSION['subcat']); 
        $_SESSION['subcat'] = mysql_real_escape_string($_GET['subcat']);
        $color= $_SESSION['subcat'];
        }
else {
    $color= "";
    };

I can echo selected in first drop down list, based on session value and that works, but a second one drop down list is not generated when page refreshes and i don’t know where should i echo ‘selected = “selected”‘ or maybe everything can be done only with javascript? Please help.

The code:

<div class="filter">
<form method="get" name="doublecombo" action="" id="filterform"  >
<select name="example" id="exampl" size="1" onChange="redirect(this.options.selectedIndex)">
<option>All kinds</option>
<option>Women</option>
<option>Men</option>
</select>
<select name="subcat" size="1" id="subcategory">
<option value="lists.php">All colors</option>
</select>
<input type="button" name="test" value="Filter" onClick="go()">
</p>

  <script>
  <!--

  /*
  Double Combo Script Credit
  By JavaScript Kit (www.javascriptkit.com)
  Over 200+ free JavaScripts here!
   */

     var groups=document.doublecombo.example.options.length
     var group=new Array(groups)
     for (i=0; i<groups; i++)
     group[i]=new Array()
     group[0][0]=new Option("All colors","list.php")

     group[1][0]=new Option("Pink","list.php?subcat=1 ")
     group[1][1]=new Option("White","list.php?subcat=2")
     group[1][2]=new Option("Green","list.php?subcat=3")


        group[2][0]=new Option("Black","list.php?subcat=12")
        group[2][1]=new Option("Blue","list.php?subcat=13")
        group[2][2]=new Option("Grey","list.php?subcat=14")
        group[2][3]=new Option("Brown","list.php?subcat=15")



        var temp=document.doublecombo.subcat

        function redirect(x){
        for (m=temp.options.length-1;m>0;m--)
        temp.options[m]=null
        for (i=0;i<group[x].length;i++){
        temp.options[i]=new Option(group[x][i].text,group[x][i].value)
         }
        temp.options[0].selected=true
         }

      function go(){
     location=temp.options[temp.selectedIndex].value
      }
       //-->
       </script>
       </form></div>
  • 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-26T23:38:43+00:00Added an answer on May 26, 2026 at 11:38 pm

    you could set a cookie to hold the selected value, so if the user selects there choice and refreshes, you would then check if the cookie exists and then populate the menus accordingly.

    Update:

    This will store the selected values and repopulate the select menus if the user refreshes the page.

    First select added onkeup:

    <select name="example" id="exampl" size="1" onchange="redirect(this.options.selectedIndex)" onkeyup="redirect(this.options.selectedIndex)">
    

    for the second select and as follows to check for changes

    <select name="subcat" size="1" id="subcategory" onchange="checks(this)" onkeyup="checks(this)">
    

    Now find the Line temp.options[0].selected=true and add this directaly below

        createCookie("selected_option_1", x, 0);
         if(x==0){
           eraseCookie("selected_option_2");
         }
    

    then add these two new function say at the bottom of your script block

     // checks if the Second Select has changed
     function checks(oWhich){
       createCookie("selected_option_2", oWhich.selectedIndex, 0);
     }
    
    // repopulate the options base on selection thats saved in the cookies 
    onload = function(){
    
    if(readCookie("selected_option_1") != null) {
    
       redirect(document.doublecombo.example.options.selectedIndex = readCookie("selected_option_1"));
    
       if(readCookie("selected_option_2") != null) {
         document.doublecombo.subcat.options.selectedIndex = readCookie("selected_option_2");
      }
    }
    
      } 
    

    Finaly for these functions/scrip to work you will need

    // The cookie script im using for the functions is located below include this and you chould ok. http://www.quirksmode.org/js/cookies.html#script

    Now once the form has been submitted you GET the selected values as usual, and the REPOPULATE the menu, once you done with the cookie you could remove them.

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

Sidebar

Related Questions

I have two Drop Down Lists, the second ones are based off which one
Currently, I have two drop down lists that are populated with users' first and
I have two drop down lists: <select name="branch"> <option value="b">Blacksburg</option> <option value="c">Christiansburg</option> <option value="f">Floyd</option>
There will be two drop down lists, First have the list of mobile vendor,
I have two drop down list on a page. The first one list projects
I have a user control in a master page with two drop down lists.
Simple ASP.NET application. I have two drop-down controls. On the first-drop down I have
I have a form with two text boxes, one select drop down and one
I have a C#.Net MVC3 web app. I am using Drop Down lists all
I have two dropdown lists, the second should only be displayed when the value

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.