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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:43:34+00:00 2026-05-23T19:43:34+00:00

At the moment I using a dynamic select to populate a dropdown. What I

  • 0

At the moment I using a dynamic select to populate a dropdown. What I would like to do is display a 2nd dropdown with results based on the selection of the first. I have no idea how to go about this and have searched for an answer but to no avail. I have included the code I using to populate the first menu, and if you need any further code, please let me know. I am quite willing to look at jQuery or javascript if someone could help with the code. Many thanks

<form id="boxform" method="post" class="webform" name="boxform" />

        <label for="company">Select a Company:</label>
                <select name="company" id="company" />
                    <option SELECTED VALUE="">Select a Company</option>
                        <?php
                          do {  
                        ?>
                    <option value="<?php echo $row_Recordsetcust['customer']?>"><?php echo $row_Recordsetcust['customer']?></option>
                        <?php

                    } 
                        while ($row_Recordsetcust = mysql_fetch_assoc($Recordsetcust));
                        $rows = mysql_num_rows($Recordsetcust);

                if($rows > 0)

                    {
                        mysql_data_seek($Recordsetcust, 0);
                        $row_Recordsetcust = mysql_fetch_assoc($Recordsetcust);
                    }

                         ?>
                 </select>

UPDATE:

This is the code for the 2nd dropdown in php format that I have at the moment if it would help move on with this, thanks

<label for="boxrtnaddress">Select Address</label>
     <select name="boxrtnaddress" id="boxrtvaddress" />
        <option SELECTED VALUE="">Select Delivery Address</option>

            <?php
            while ($row_rs_select_address2 = mysql_fetch_assoc($rs_select_address2))
            {  
                    $value=$row_rs_select_address2['address1_com']. " ". $row_rs_select_address2['address2_com']. " ". $row_rs_select_address2['address3_com']. " ". $row_rs_select_address2['town_com']. " ". $row_rs_select_address2['postcode_com'];
                    $caption=$row_rs_select_address2['address1_com']. " ". $row_rs_select_address2['address2_com']. " ". $row_rs_select_address2['address3_com']. " ". $row_rs_select_address2['town_com']. " ". $row_rs_select_address2['postcode_com'];
                    echo "<option value=\"", $value, "\">", $caption, "</option>";
            }
            ?>
    </select>

+++++++++++++SOLUTION++++++++++

<script language="javascript" type="text/javascript" src="http://code.jquery.com/jquery-1.6.2.min.js"></script>
<script language="javascript" type="text/javascript">
      $(function() {
            $("#company").change(function() {
              if ($(this).val()!="") $.get("getOptions.php?customer=" + $(this).val(), function(data) {
                $("#divId").html(data);
                });
              });
      });
</script>

getOptions.php

<?php
    $customer = mysql_real_escape_string( $_GET["customer"] ); // not used here, it's the customer choosen

    $con = mysql_connect("localhost","root","");
    $db = "sample";
      if (!$con)
        {
        die('Could not connect: ' . mysql_error());
        }

        mysql_select_db($db, $con);
        $query_rs_select_address2 = sprintf("SELECT * FROM company_com where idcode_com = '$customer'");
        $rs_select_address2 = mysql_query($query_rs_select_address2, $con) or die(mysql_error());
        $row_rs_select_address2 = mysql_fetch_assoc($rs_select_address2);
        $totalRows_rs_select_address2 = mysql_num_rows($rs_select_address2);



                    $address=$row_rs_select_address2['address1_com']. " ". $row_rs_select_address2['address2_com']. " ". $row_rs_select_address2['address3_com']. " ". $row_rs_select_address2['town_com']. " ". $row_rs_select_address2['postcode_com'];
                     echo '<select name="customer">'.'<option value="">Select delivery address</option>'.'<option value="address">'.$address.'</option>'.'</select>';



?>
  • 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-23T19:43:35+00:00Added an answer on May 23, 2026 at 7:43 pm

    it may help, here is a fiddle

    http://jsfiddle.net/gZzQr/

    that dynamically appends a select based on the selection of first select the code is messy and dirty so im not gonna post it here 🙂

    you can have a look at the following to better understand the working

    change triggers when the selected value of a select is changed

    is(':empty') checks whether the div to which the newly created `select
    is to be appended is empty or not

    http://api.jquery.com/is/

    http://api.jquery.com/empty/

    Edit
    i’ll give you hints hopefully you’ll fill in the rest of code…

    first of all what you need to do is handle the change event of your first drop down and when the value changes you can do an ajax, get, post request to your server, fetch the results and populate the second drop down, here is a useful stackoverflow link that may help you

    php dropdown menu population

    $("#firstDD").change(function(){
    var value = $(this).val();//get the changed value of first dd(drop down)
    
    
    //now do a post request 
    
    $.post("results.php",{data:value},function(data){
    //get the values here and populate the second drop down
    
    });
    
    });
    

    in your results.php

    get the value from first drop down

    $val = $_POST['data'];
    //now do the sql queries to fetch desired result
    //and echo the results back
    
    echo $results ;
    

    here are some useful links

    http://www.prodevtips.com/2008/08/15/jquery-json-with-php-json_encode-and-json_decode/

    http://api.jquery.com/jQuery.post/

    http://www.factsandpeople.com/facts-mainmenu-5/26-html-and-javascript/89-jquery-ajax-json-and-php

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

Sidebar

Related Questions

I have a Java client that calls a web service at the moment using
I have a self built JSP webapp and at the moment I'm using tomcats
i have a submission of different color hexs. At the moment im using a
We are using Apache Velocity for dynamic templates. At the moment Velocity has following
I have a Masterpage (site.master) that calls a View using RenderAction. At the moment
I have the need to return tree like results from a single table. At
I am making a little GUI frontend for a app at the moment using
I am using Oracle 10g at the moment. I want to search through all
I am using in my code at the moment a ReentrantReadWriteLock to synchronize access
I am using VMware Server 1.0.7 on Windows XP SP3 at the moment to

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.