Here is my code.
<div class="col-sm-12">
<div class="col-sm-5">
<?php
$query=$conn->query("Select * From countries Where status='1' ORDER BY country_name ASC");
$rowcount=$query->num_rows;
?>
<label for="Country">Country<sup>*</sup></label>
<!-- <input class="form-field" name="entity" id="name" type="text" placeholder="Your country">-->
<select name="country" id="country" class="form-field" value="<?php echo $country; ?>">
<option value="">Select Country</option>
<?php
if($rowcount>0){
while($row=$query->fetch_assoc()){
echo '<option value="'.$row['country_id'].'">'.$row['country_name'].'</option>';
}
}
else{
echo '<option value="">Country Not Available</option>';
}
?>
</select>
<script type="text/javascript">
document.getElementById('country').value = "<?php if(empty($others))
{
echo $_POST['country'];
}?>";
</script>
</div>
<div class="col-sm-2"></div>
<div class="col-sm-5">
<label for="State">State<sup>*</sup></label>
<select name="state" id="state" class="form-field" value = "<?php echo states;?>">
<option>Select Country First</option>
</select>
<script type="text/javascript">
document.getElementById('state').value = "<?php echo $_POST['state'];?>";
</script>
</div>
</div>
</div>