In my HTML, I have two select boxes: the first for Country and the second for City. The requirement is to display a textbox when a user selects a country other than Pakistan and show a dropdown list for city if the user selects Pakistan from the country dropdown.
Below is the code snippet that I attempted:
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post">
<div class="form-group col-md-3">
<label for="cc-payment" class="control-label mb-1">Birth Country</label>
<select class="form-control" name="Birth_Country" id="Birth_Country" style="color: black;" required>
<option value="">Please Select Birth Country</option>
<?php
$sel_cus = "select Country_Name from personal_country_name Order By Country_Name";
$res_cus = mysqli_query($connection, $sel_cus);
while ($row = mysqli_fetch_array($res_cus)) {?>
<option value="<?php echo $row['Country_Name'];?>"><?php echo strtoupper($row['Country_Name']);?></option>
<?php
}
?>
</select>
</div>
<div class="form-group col-md-3">
<label for="cc-payment" class="control-label mb-1">Birth City</label>
<select class="form-control" name="Birth_City" id="Birth_City" style="color: black;" required>
<option value="">Please Select Birth City</option>
<?php
$sel_cus = "select city_name from personal_city_name order By city_name";
$res_cus = mysqli_query($connection, $sel_cus);
while ($row = mysqli_fetch_array($res_cus)) {?>
<option value="<?php echo $row['city_name'];?>"><?php echo strtoupper($row['city_name']);?></option>
<?php
}
?>
</select>
<input type="text" autocomplete="off" onkeyup="this.value = this.value.toUpperCase();" class="form-control" name="Other_Birth_City" id="other" style="color: black;" value="<?php echo $data['Birth_City']?>" required data-toggle="tooltip" title="Birth City" placeholder="Birth City"/>
</div>
<button type="submit" class="btn btn-primary pull-right" style="margin-right: 430px; width: 105px; height: 42px; margin-top: 22px;" value="Save" name="Save" id="Save">Save</button>
</form>