I need to get the value of the selected items on the first dropdown because on the second drop down the list that will be shown will depend on the value from the first drop down. Here's my coding. By the way I am using PHP.
In here I am displaying the list of region, then when region is already selected the province that are only under that region should be displayed in the second drop down.
First drop down:
<p><b>Region:</b>
<select class="w3-select" name="region" id="region_value"
onChange="myFunction()" required>
<option value="">--- Select Region ---</option>
<?php
$Region = $FormModel->RegionList();
foreach($Region as $RegionList) {
?>
<option id="option" value="<?php echo $RegionList['region_code']?>"><?php
echo $RegionList['region_name'] ?> </option> </p>
<?php } ?>
</select>
Second drop down:
<p><b>Province:</b>
<select class="w3-select" name="province" id="demo" required>
<option value="">--- Select Province ---</option>
<?php
$Province = $FormModel->ProvinceList();
foreach($Province as $ProvinceList) {
?>
<option value="<?php echo $ProvinceList['prov_code']?>"> <?php echo
$ProvinceList['prov_name'] ?> </option> </p>
<?php } ?>
</select>
I have a java script here getting the value of the selected items but I don't know how to pass it as an attribute to set the value as the region code. I have a setter and getter in which I will set first the region code and in my query I am getting the value of the region code. But it's not working.
<script>
function myFunction() {
var x = document.getElementById("region_value").value;
$FormModel = new Form(x);
}
</script>
Here's my query where I get the list of province.
public function ProvinceList(){
$region = $this->getRegion();
$sql = "SELECT prov_code,psgc_prv, prov_name FROM lib_provinces WHERE
region_code='$region' ORDER BY prov_name";
$this->openDB();
$this->prepareQuery($sql);
$result = $this->executeQuery();
$recordlist = array();
$trash = array_pop($recordlist);
foreach($result as $i=>$row){
$row_data = array(
"prov_code"=>$row["prov_code"],
"psgc_prv"=>$row["psgc_prv"],
"prov_name"=>$row["prov_name"]
);
$recordlist[$i] = $row_data;
}
$this->closeDB();
return $recordlist;
}
I would be a great help if someone can answer me in this work around.Thanks!