would really appreciate your help on below issue. I have 3 dynamic dependent dropdowns. Scheme 1 is working when: Click Dropdown (Dd) 1=>Values change in Dd2=>Values change in Dd3. But I need Dd3 to be also dependent on Dd1 & Dd2. I have ajax code and suppose it has mistakes:
$(document).ready(function(){
$('#country', '#state').on('change',function(){
var countryID = $('#country').val();
var stateID = $('#state').val();
if(countryID, stateID){
$.ajax({
type:'POST',
url:'search_city.php',
data: "country_id="+countryID+"&state_id="+stateID,
success:function(html){
$('#city').html(html);
}
});
}else{
$('#city').html('<option value="">Select state first</option>');
}
})
});
ADDING PHP FILE:
<?php
include('connect.php');
if (isset($_POST["country_id"] || isset($_POST["state_id"]))) {
$query = $conn->query("SELECT * FROM city WHERE country_id =
".$_POST['country_id']." AND state_id = ".$_POST['state_id']." ORDER BY
city_name");
$rowCount = $query->num_rows;
if($rowCount > 0){
echo '<option value="">Select city</option>';
while($row = $query->fetch_assoc()){
echo '<option
value="'.$row['city_id'].'">'.$row['city_name'].'</option>';
}
}else{
echo '<option value="">City not available</option>';
}
}
?>