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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:46:51+00:00 2026-06-12T22:46:51+00:00

I have two chained select boxes where the second drop down populates based on

  • 0

I have two chained select boxes where the second drop down populates based on the value of the first drop down and that works well. I currently have a php function that retrieves and displays the values of the selectboxes when users click on a button. Now the challenge I have is because they have to click the button to display the options they selected, the page is refreshed but I want a way where the options selected can be retrieved and displayed so the users can see what they choose without the page refreshing. I know this can be achieved using ajax but I am new to ajax and I have checked so many similar problems online but I do not quite understand how to make this work. Any advise on this will be very much appreciated. Please see below my php function that performs the retrieve and display of the selected values

function OutputCategory() {
    if (isset($_POST['drop_2']) && ($_POST['btn_confirm']) && ($_POST['drop_1'])) {
        $drop2 = $_POST['drop_2'];
        $drop1 = $_POST['drop_1'];

        $cat_name = mysql_query(sprintf("SELECT subcategory_name FROM subcategory WHERE subcategory_id = '%s'", mysql_real_escape_string($drop2)));
        while ($cat_name1 = mysql_fetch_array($cat_name)) {
            $cat_name2 = $cat_name1['subcategory_name'];
        }

        $cat = mysql_query(sprintf("SELECT category_name FROM category WHERE category_id = '%s'", mysql_real_escape_string($drop1)));
        while ($cat1 = mysql_fetch_array($cat)) {
            $cat_2 = $cat1['category_name'];
        }
        echo "You selected Category:";
        echo $cat_2." >> ".$cat_name2;
    }
    elseif(isset($_POST['drop_1']) && ($_POST['btn_confirm'])) {
        $drop1 = $_POST['drop_1'];
        $cat = mysql_query(sprintf("SELECT category_name FROM category WHERE category_id = '%s'", mysql_real_escape_string($drop1)));
        while ($cat1 = mysql_fetch_array($cat)) {
            $cat_2 = $cat1['category_name'];

            echo "You selected Category:";
            echo $cat_2;
        }
    }
}​
  • 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-12T22:46:51+00:00Added an answer on June 12, 2026 at 10:46 pm

    You need to bind an ajax call to the select, something like this:

    $('#select1_id').on('change', function() {
      $.ajax({
        type: 'GET',
        data: {
          'select1_val': $(this).val()
        },
        url: 'some_page.php',
        success: function( data ) {
          $select2 = $('#select2_id');
          $select2.empty();      
    
          $(data.options).each(function(i,option){
            // append option to $select2
          });
        } 
    
      });
    });
    

    Then, on “some_page.php”, hae something like this:

    if( $_GET['select1_val'] ) {
    
      // get the select 2 vals, put them into an $array
      json_encode(array('options' => $array )); exit;
    
    }
    

    … although this is of course a very simple example, I’m sure you get the idea

    Cheers,

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

Sidebar

Related Questions

I have a series of two chained selects using ajax that work great. I
I have two chained CascadingDropDowns . Both are working fine. The thing is that
Background I have two select form fields chained together: duration and frequency. When the
The problem I have is to pass the chained search of two models to
I have created a pair of chained selectboxes in my page. The second selectbox
Have two issues one is showFromToolbar statement format warning issue and another is that
I'm trying to create a simple chained ( http://www.appelsiini.net/projects/chained ) select box that ends
I have two tables that have the same structure, I need a query to
I have two applications written in Java that communicate with each other using XML
have two three tables one for student, second for class, and the third for

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.