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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:12:08+00:00 2026-05-24T03:12:08+00:00

I have database consists of countries and cities. First Case – Successfully done: Country

  • 0

I have database consists of countries and cities.

First Case – Successfully done:

  1. Country list gets populated in drop box on page load
  2. City list gets populated in drop box on page load – populated city list
    is based on the default country.

Second Case – Couldn’t make it:

  1. User changes country
  2. City list will be changed according to selected country

I know i have to use jQuery/Ajax. I tried but i couldn’t solve my problem due to my lack of programming experience. My list is fetched from database not XML. I just need a quick solution, i need to keep it simple and stupid.

I’m using regular PHP coding style, not Object-Oriented.

How can i do it? Any related resources will be appreciated.

  • 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-24T03:12:09+00:00Added an answer on May 24, 2026 at 3:12 am
    $("#country").change(function(){
        $('#city').find('option').remove().end(); //clear the city ddl
        var country = $(this).find("option:selected").text();
        alert(country);
        //do the ajax call
        $.ajax({
            url:'getCity.php'
            type:'GET',
            data:{city:country},
            dataType:'json',
            cache:false,
            success:function(data){
    
            data=JSON.parse(data); //no need if dataType is set to json
             var ddl = document.getElementById('city');                      
    
             for(var c=0;c<obj.length;c++)
                  {              
                   var option = document.createElement('option');
                   option.value = obj[c];
                   option.text  = obj[c];                           
                   ddl.appendChild(option);
                  }
    
    
        },
            error:function(jxhr){
            alert(jxhr.responseText);
    
        }
        }); 
    
    });
    

    in your getCity.php

    $country = $_GET['city'];
    
    //do the db query here
    
    $query  = "your query";
    $result = mysql_query($query);
    $temp = array();
    while ($row = mysql_fetch_assoc($result)) {
    
     if(empty($temp))
     {
       $temp=array($row['city']);
     }
     else
     {  
       array_push($temp,$row['city']);
     }
    
    }
    echo (json_encode($temp));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of countries in a database. I have created a select
Let's say I have a large database that consists of products in groups. Let's
I'm currently trying to optimize my program. I have a large database which consists
I have a huge database (800MB) which consists of a field called 'Date Last
I have a MS access database. In that, one table consists of questions and
I have a database that consists of 5 tables : Course, Category, Location, CourseCategories,
Lets say I have a database table which consists of three columns: id ,
Consider a database(MSSQL 2005) that consists of 100+ tables which have primary keys defined
I have 3 arrays coming from a webservice... Countries : Consists of Key -
I have a database that consists of two tables, which look like this: users

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.