Nick Kahn
Nick Kahn

Reputation: 20078

Load Country/State/City

I have chain of drop down like Country / state and City. Is there is any way to wait until the drop down population then proceed further? like first load the country and then based on the select of an country then load the state and same as city....

function populateLists(listType) {
    // on success do this:
    $.ajax({
    type:"POST",
    url:"Wizard_Using_PageMethod.aspx/GetCountry",
    data: "{}",
    contentType: "application/json; charset=utf-8",
    dataType:"json"}
});

[WebMethod]
public static CountryList GetCountry()
{
    CountryList country = new CountryList();
    ///go to db and get the data
    return country;
}

Upvotes: 2

Views: 7741

Answers (1)

mizno kruge
mizno kruge

Reputation: 31

You may do like this

$('#cb_country').change(function(){
    var id=$(this).val();
    $.get('getCity.php',{id:id},function(data){
        $("#cb_city").html(data);
    });
});

getCity.php:

<?php
require('../conn.php');

$id=$_GET['id'];
$Q=mysql_query("SELECT * FROM city WHERE CountryID='".$id."' ORDER BY Cityname ASC");

do{
    echo "<option value='".$row['CityID']."'>".$row['CityName']."</option>";
}
while($row=mysql_fetch_assoc($Q));

Upvotes: 3

Related Questions