0

How I can write down a code which uses two Two AJAX-es in combo-boxes?
For Country, when user clicks Country combo-box, State Combo-box will fetch with respective Country, and if when user clicks State combo-box, cities Combo-box will fetch with respective State. All data will came from database. I successfully populate for the Country but not for State

Edited by abhi10kumar: Not full info.

3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by happytogether
0

try to use jQuery

$("#id of of box when you click will do this function").click(function(){
$.get('getcountry.php', function(data) {
	$('# id of your box where you want to display the result').html(data);
});
});

in youre getcountry.php

$getCountry = mysql_query("select Name from Country");
		$gco = '<option value="">Select Country </option>';
		while($CountryName = mysql_fetch_array($getCountry)){
		$gco .='<option value="'.$CountryName['Name'].'">'.$CountryName['Name'].'</option>';
	}
	echo $gco;

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

0
<select name="country" id="country"></select>
<select name="state" id="state"></select>
<select name="cities" id="cities"></select>

$("#country").click(function(){
	$.get('getstate.php', function(data) {
	$('#state).html(data);
	});
});

$("#state").click(function(){
	$.get('getcities.php', function(data) {
	$('#cities).html(data);
	});
})

getstate.php

$getstate = mysql_query("select state from table where country='".$_POST['country']."'");
		while($StateName = mysql_fetch_array($getstate)){
		echo '<option value="'.$StateName['state'].'">'.$StateName['state'].'</option>';
	}

getcities.php

$getcities = mysql_query("select cities from table where state='".$_POST['state']."'");
		while($CitiesName = mysql_fetch_array($getcities)){
		echo '<option value="'.$CitiesName['cities'].'">'.$CitiesName['cities'].'</option>';
}

and dont forget to download http://code.jquery.com/jquery-1.5.1.min.js

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.