I have dropdown which when any option in it selected, another dropdown values should populate.
I need to check that first drop down value with some variable and based on that condition other drop down values populate based on it.
My first dropdown,
<select id="mySelect" name="name">
<option>Select any city</option>
<?php foreach ($data as $c) { ?>
<option><?php echo ($c[0]['value']); ?></option>
<?php } ?>
</select>
Am gettting the above dropdown selected value using jquery, but i need in php
jQuery("#mySelect").change(function () {
...
});
For second dropdown,
<select>
......
if ($myPhpVar == $data[1][$j][$i]['c_name']){ ?>
<option><?php echo $data[1][$j][$i]['a_name']; ?></option>
<?php }
.... ?>
</select>
here $myPhpVar
should be first dropdown selected value, I need to compare it with some data.
How to get the first dropdown value and set it to $myPhpVar
UPDATE:
Managed drop down using jQuery:
jQuery("#mySelect").change(function () {
var end = this.value;
var firstDropVal = jQuery('#mySelect').val();
<?php for($j=0; $j<count($data[1]); $j++ ){
//print_r ($data[1][$j]);
for($i=0; $i<count($data[1][$j]);$i++){
if ($myPhpVar == $data[1][$j][$i]['city_name']){
echo $data[1][$j][$i]['area_name']; ?>
jQuery('#dsad').append("<option><?php echo json_encode($data[1][$j][$i]['area_name']); ?></option> ")
<?php
}
}
} ?>
console.log(end);
console.log(firstDropVal);
});
Yet not getting dropdown values for the second dropdown.