Когда я нажимаю кнопку отправки, сбрасывается только одно значение поля. Я указал такие поля, как город штата и местоположение в раскрывающемся списке, и нет проблем с выбором штата и города, но выбранное местоположение сбрасывается, когда я нажимаю кнопку отправки. Я указал так много городов в рамках штата и указал местоположения в рамках города, когда я выбираю штат, город в этом конкретном штате появляется в раскрывающемся поле города.
<div class="form-group col-md-12">
<h5>Locations <span class="text-danger">*</span></h5>
</div>
<div class="form-group col-md-4">
<h5>State <span class="text-danger">*</span></h5>
</div>
<div class="form-group col-md-4">
<h5>City <span class="text-danger">*</span></h5>
</div>
<div class="form-group col-md-4 d-flex ">
<h5>Location <span class="text-danger">*</span></h5>
<a href="manage_company.php<?php $flag++; if($id!=''){ echo '?id='.$id.'&flag='.$flag; } else { echo '?flag='.$flag; } ?>" class="add_button btn btn-primary ml-5" title="Add New Location"><i class="fa fa-plus"></i> Add New</a>
</div>
<?php
$select_count = 1;
if($location_map==''){
?>
<div class="form-group col-md-4">
<!-- <h5>State <span class="text-danger">*</span></h5> -->
<div class="controls">
<select class="select2 form-control custom-select" id="state<?php echo $select_count; ?>" name="state[]" style="width: 100%; height:36px;" onchange="selectState(this.value,<?php echo $select_count; ?>);" >
<option>Select State</option>
<?php
foreach($states as $state){
?>
<option value="<?php echo $state['id']; ?>" <?php if($state_id==$state['id']) echo "selected"; ?> ><?php echo $state['state_name'] ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="form-group col-md-4">
<!-- <h5>City <span class="text-danger">*</span></h5> -->
<div class="controls">
<select class="select2 form-control custom-select" id="city<?php echo $select_count; ?>" name="city[]" style="width: 100%; height:36px;" required data-validation-required-message="This field is required" onchange="selectCity(this.value,<?php echo $select_count; ?>);" >
<option>Select City</option>
<?php
foreach($cities as $city){
?>
<option value="<?php echo $city['id']; ?>" <?php if($city_id==$city['id']) echo "selected"; ?> ><?php echo $city['city_name'] ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="form-group col-md-4">
<!-- <h5>Location <span class="text-danger">*</span></h5> -->
<div class="controls">
<select class="select2 form-control custom-select" id="location<?php echo $select_count; ?>" name="location[]" style="width: 100%; height:36px;" required data-validation-required-message="This field is required" >
<option>Select Location</option>
<?php
foreach($locations as $location){
?>
<option value="<?php echo $location['id']; ?>" <?php if($location_id==$location['id']) echo "selected"; ?> ><?php echo $location['location_name'] ?></option>
<?php } $select_count++; ?>
</select>
</div>
</div>
<?php
}
if($location_map!=''){
foreach($location_map as $mlocation){
?>
<div class="form-group col-md-4">
<!-- <h5>State <span class="text-danger">*</span></h5> -->
<div class="controls">
<select class="select2 form-control custom-select" id="state<?php echo $select_count; ?>" name="state[]" style="width: 100%; height:36px;" required data-validation-required-message="This field is required" onchange="selectState(this.value,<?php echo $select_count; ?>);" >
<option>Select State</option>
<?php
foreach($states as $state){
?>
<option value="<?php echo $state['id']; ?>" <?php if($mlocation['state_id']==$state['id']) echo "selected"; ?> ><?php echo $state['state_name'] ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="form-group col-md-4">
<!-- <h5>City <span class="text-danger">*</span></h5> -->
<div class="controls">
<select class="select2 form-control custom-select" id="city<?php echo $select_count; ?>" name="city[]" style="width: 100%; height:36px;" required data-validation-required-message="This field is required" onchange="selectCity(this.value,<?php echo $select_count; ?>);" >
<option>Select City</option>
<?php
foreach($cities as $city){
?>
<option value="<?php echo $city['id']; ?>" <?php if($mlocation['city_id']==$city['id']) echo "selected"; ?> ><?php echo $city['city_name'] ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="form-group col-md-4">
<!-- <h5>Location <span class="text-danger">*</span></h5> -->
<div class="controls">
<select class="select2 form-control custom-select" id="location<?php echo $select_count;?>" name="location[]" style="width: 100%; height:36px;" required data-validation-required-message="This field is required">
<option >Select Location</option>
<?php
foreach($locations as $location){
?>
<option value="<?php echo $location['id']; ?>" <?php if($mlocation['location_id']==$location['id']) echo "selected"; ?> ><?php echo $location['location_name'] ?></option>
<?php } $select_count++; ?>
</select>
</div>
</div>
<?php
}
}
if(isset($_REQUEST['flag'])){
for ($x = 1; $x < $flag; $x++) {
?>
<div class="form-group col-md-4">
<!-- <h5>State <span class="text-danger">*</span></h5> -->
<div class="controls">
<select class="select2 form-control custom-select" id="state<?php echo $select_count; ?>" name="state[]" style="width: 100%; height:36px;" required onchange="selectState(this.value,<?php echo $select_count; ?>);" >
<option>Select State</option>
<?php
foreach($states as $state){
?>
<option value="<?php echo $state['id']; ?>" <?php if($state_id==$state['id']) echo "selected"; ?> ><?php echo $state['state_name'] ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="form-group col-md-4">
<!-- <h5>City <span class="text-danger">*</span></h5> -->
<div class="controls">
<select class="select2 form-control custom-select" id="city<?php echo $select_count; ?>" name="city[]" style="width: 100%; height:36px;" required data-validation-required-message="This field is required" onchange="selectCity(this.value,<?php echo $select_count; ?>);" >
<option>Select City</option>
<?php
foreach($cities as $city){
?>
<option value="<?php echo $city['id']; ?>" <?php if($city_id==$city['id']) echo "selected"; ?> ><?php echo $city['city_name'] ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="form-group col-md-4">
<!-- <h5>Location <span class="text-danger">*</span></h5> -->
<div class="controls ">
<select class="select2 form-control custom-select" id="location<?php echo $select_count;?>" name="location[]" style="width: 100%; height:36px;" required data-validation-required-message="This field is required">
<option>Select Location</option>
<?php
foreach($locations as $location){
?>
<option value="<?php echo $location['id']; ?>" <?php if($location_id==$location['id']) echo "selected"; ?> ><?php echo $location['location_name'] ?></option>
<?php
}
$select_count++;
?>
</select>
</div>
</div>
<?php
}
}
?>