My FrontEnd Code:
<div class="form-group col-md-3">
<label for="taluka">Select Taluka</label>
<select name="taluka" id="taluka" required class="form-control">
<option value="" selected disabled>Select Taluka</option>
<?php $Adder->listTalukas(); ?>
</select>
</div>
<div class="form-group col-md-3">
<label for="city">Select City</label>
<select name="city" id="city" required class="form-control">
<option value="" selected disabled>Select City</option>
</select>
</div>
<div class="form-group col-md-3">
<label for="pincode">Select pincode</label>
<select name="pincode" id="pincode" required class="form-control">
<option value="" selected disabled>Select pincode</option>
</select>
</div>
This is my JQuery code:
$(document).ready(function()
{
$("body").on("click", "select#taluka option",function()
{
var taluka_id = $("#taluka").val();
if(taluka_id != "")
{
$.ajax({
url: 'get_data.php?id=getCity',
type: 'POST',
dataType: 'html',
data: {taluka_id : taluka_id},
})
.done(function(resp)
{
$("#city").html("<option value='' selected disabled>Select City</option>");
$("#pincode").html("<option value='' selected disabled>Select Pincode</option>");
$("#city").append(resp);
})
.fail(function()
{
console.log("error");
});
}
});
$("body").on("click", "select#city option",function()
{
var city_id = $("#city").val();
if(city_id != "")
{
$.ajax({
url: 'get_data.php?id=getPincode',
type: 'POST',
dataType: 'html',
data: {city_id : city_id},
})
.done(function(resp)
{
$("#pincode").html("<option value='' selected disabled>Select Pincode</option>");
$("#pincode").append(resp);
})
.fail(function()
{
console.log("error");
});
}
});
});
The get_data.php file that i am calling through JQuery:
<?php
if(extract($_POST) > 0)
{
$id = $_GET['id'];
include("config.php"); include("classes.php");
switch($id)
{
case 'getCity':
echo $Adder->listCities($_POST['taluka_id']);
break;
case 'getPincode':
echo $Adder->listPincodes($_POST['city_id']);
break;
default:
// echo "None";
break;
}
}
?>
The code is working fine it is sending the POST request as well as getting the response also the problem is that the click event is only triggered in mozilla firefox browsers. It doesn't work in chrome as well as mobile touchscreen browsers why so ?
Please provide a solution. Thanks in advance