<section class="col col-6">
<label class="select">
<span style="color:red;">*</span>
<select name="country" class="select2" onChange="getState(this.value);">
<option value="">Country</option>
<?php
$coun=mysql_query("select * from country");
while($rows=mysql_fetch_array($coun))
{
?>
<option value="<?php echo $rows['c_id']; ?>"><?php echo $rows[1]; ?></option>
<?php
}
?>
</select> </label>
</section>
<section class="col col-6">
<span style="color:red;">*</span>
<label class="select">
<select name="state" class="select2" id="state-list">
<option value="">State</option>
</select> </label>
</section>
<!-- country -->
<script>
function getState(val) {
$.ajax({
type: "POST",
url: "get_state.php",
data:'c_id='+val,
success: function(data){
$("#state-list").html(data);
}
});
}
function selectCountry(val) {
$("#search-box").val(val);
$("#suggesstion-box").hide();
}
</script>
<!-- end Country -->
===============
get_state.php
==========================
<?php
include("connection.php");
$id=$_POST['c_id'];
if($id == 76) {
$id1=76;
}
else
{
$id1=0;
}
$query ="SELECT * FROM `tbl_state` WHERE c_id = '$id1'";
$results = mysql_query($query);
?>
<option value="">Select State</option>
<?php
while($row=mysql_fetch_array($results))
{
?>
<option value="<?php echo $row["state_id"]; ?>"><?php echo $row["state_name"]; ?></option>
<?php
}
?>
<label class="select">
<span style="color:red;">*</span>
<select name="country" class="select2" onChange="getState(this.value);">
<option value="">Country</option>
<?php
$coun=mysql_query("select * from country");
while($rows=mysql_fetch_array($coun))
{
?>
<option value="<?php echo $rows['c_id']; ?>"><?php echo $rows[1]; ?></option>
<?php
}
?>
</select> </label>
</section>
<section class="col col-6">
<span style="color:red;">*</span>
<label class="select">
<select name="state" class="select2" id="state-list">
<option value="">State</option>
</select> </label>
</section>
<!-- country -->
<script>
function getState(val) {
$.ajax({
type: "POST",
url: "get_state.php",
data:'c_id='+val,
success: function(data){
$("#state-list").html(data);
}
});
}
function selectCountry(val) {
$("#search-box").val(val);
$("#suggesstion-box").hide();
}
</script>
<!-- end Country -->
===============
get_state.php
==========================
<?php
include("connection.php");
$id=$_POST['c_id'];
if($id == 76) {
$id1=76;
}
else
{
$id1=0;
}
$query ="SELECT * FROM `tbl_state` WHERE c_id = '$id1'";
$results = mysql_query($query);
?>
<option value="">Select State</option>
<?php
while($row=mysql_fetch_array($results))
{
?>
<option value="<?php echo $row["state_id"]; ?>"><?php echo $row["state_name"]; ?></option>
<?php
}
?>
No comments:
Post a Comment