take value from another input without refreshing page in php

i have this fetch.php file

 $out='';
 while($row = mysqli_fetch_assoc($result)) {
 $out .=  '<option value='.$row["jam_mulai"].'>' .$row["jam_mulai"]. '-.$row["jam_berakhir"].'</option>'; 
} 
 echo $out;

and i want to take the data from the option value to another select option in different file.
to this input.php file

 <select class="form-control select2" name="nama_dokter" style="width: 100%;" id="nama_dokter">
                        <option value="" selected="true" disabled="disabled">Pilih Dokter</option>
                    <?php
                         $query  = mysqli_query($koneksi, "SELECT * FROM jadwal_praktek LEFT JOIN dokter
                                  ON jadwal_praktek.dokter_id=dokter.id WHERE status='Aktif' GROUP BY dokter_id");
                        while ($data = mysqli_fetch_array($query)){
                    ?>  

                       <option value="<?= $data['id_jadwal'];?>"><?php echo $data['nama_dkt'];?></option>
                    <?php } ?>
                    </select>

so i want that if jam_mulai that user choose is same with the jam_mulai and dokter_id that are already in the database, so the value of option value (input.php) will be inserted as the jadwal_id.

i have doctors (dokter_id) that have one or more than one schedule (jadwal_id) with different time (jam_mulai)

here’s the schedule table

i know its really confusing, i also find it confusing to explain, but that what i meant. if someone may know the solution, please reply. thanks in advance.