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

The Archive Base Latest Questions

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

I have 2 tables, Provinces and Districts. I would like to populate a select

  • 0

I have 2 tables, Provinces and Districts. I would like to populate a select field with options as District names based on which Province is chosen in another select. The Districts table has a ProvinceID field to reference which Province it belongs to. I know this is doable, I just can’t figure it out. I also want to create and update the new Districts select without refreshing the page.

UPDATE: I’m writing it in PHP and MySQL, using jQuery as sparingly as possible.

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

    I actually figured this out on my own using jQuery and post. On the primary select, I added onchange=”getDistricts()” and used this for that function:

    function getDistricts()
    {
        var province_id = $("#provinces").val();
        $.post("handler.php",
        {
            "mode" : "get_districts",
            "pid" : province_id
        },
        function(data)
        {
            $("#districts").html(data);
        }, "text");
    }
    

    And then in handler.php, I have a case that catches the mode, and runs the following code:

    <query on districts table>
    while($row = $sql->fetchrow($result);
    {
        $id = $row['id'];
        $name = $row['name'];
        $html .= "<option value='$id' id='$id'>$name</option>";
    }
    echo $html;
    

    I’m not a fan of this solution, and would really like something better, but it does what I need it to do for the moment. I hope this can help someone else out.

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

Sidebar

Related Questions

I have a small db, nothing fancy just 5 tables. I would like to
I have two tables, one containing a list of different options users can select
I have tables like this: tblUsers int UserID string UserName tblUsersInRoles int UserID int
hi i have tables like this: Persons: person_id, name then i have many langauge
Consider a database(MSSQL 2005) that consists of 100+ tables which have primary keys defined
I have a MySQL database that has a few very simple tables. I would
I have a complex view, which is described here: View of multiple tables. Need
I have the following code which formats a table on a webpage like this:
I have two tables: countries: province, country, lat, lng reports: title, province, country, lat,
I have a data set (currently in Access 2007 format) which has 2 tables,

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.