I am attempting to make dynamic dropdown boxes a search tool to help narrow down display data from a mysql server. I am a decent php programmer but need help with the javascript and ajax.
i use below code for drop down list with ajax but when choose one potion from first listbox nothing view in next list box
please help me?
ostan.php:
<head>
<script>
$(function (){ //document is loaded so we can bind events
$("#ali").change(function (){ //change event for select
$.ajax({ //ajax call
type: "POST", //method == POST
url: "getshahr.php", //url to be called
data: { ali: $("#ali option:selected").val()} //data to be send
}).done(function( msg ) { //called when request is successful msg
//do something with msg which is response
$("#txtHint").html(msg);
});
});
});
</script>
</head>
<?php
//db connection info.
$dbuser = 'root';
$dbhost = 'localhost';
$dbpass = '';
$dbname = 'tutorial';
$mysql_link = mysql_connect($dbhost,$dbuser,$dbpass) or die ("Could not connect");
mysql_select_db ($dbname) or die ("DB select failed"); //select db
$query = "select DISTINCT ostan from com"; //get product count by groups of products
$result = mysql_query($query); //queryresult1
echo '<select id="ali">';
while($row = mysql_fetch_array($result))
{
echo '<option id="'.$row['ostan'].'">'.$row['ostan'].'</option>';
}echo "</select><br /><br ><div id=\"txtHint\"><select name='select'>
<option>Select City</option>
</select></div>";
?>
getshahr.php:
<?php
//db connection info.
$dbuser = 'root';
$dbhost = 'localhost';
$dbpass = '';
$dbname = 'tutorial';
$mysql_link = mysql_connect($dbhost,$dbuser,$dbpass) or die ("Could not connect");
mysql_select_db ($dbname) or die ("DB select failed"); //select db
$query = "select shahr from com where ostan='{$_POST["ali"]}'";
$result = mysql_query($query); //queryresult1
echo '<select id="ali">';
while($row = mysql_fetch_array($result))
{
echo '<option id="'.$row['shahr'].'">'.$row['shahr'].'</option>';
}
echo "</select><br /><br />";
?>