从第一个选择框中选择后,如何填充第二个选择框

I m developing a quiz site, in which i want to select subjects (second option) after making selection from class (first option)

i have tried many of the solutions find there but no one suits with me code

First Option Select Class

$selectclass="SELECT id , classname FROM classes";
$selectclasses = mysqli_query($connectionglobal, $selectclass);
if(mysqli_num_rows($selectclasses) > 0){
while($row = mysqli_fetch_array($selectclasses)){?>
 <option value="<?php echo $row['id']; ?>">
<?php $classids=$row['id']; echo "$row[classname]";}}?>
</option></select>                

Second Option

 <label>Select Course</label>
<select class="form-control border-success" name="subject" id="subject">
<option selected="" disabled > Select Subject</option>
<?php
$selectsubj="SELECT id , coursecode , classid FROM courses";
$selectsubject = mysqli_query($connectionglobal, $selectsubj);
                                           if(mysqli_num_rows($selectsubject) > 0){
while($rows = mysqli_fetch_array($selectsubject)){?>
<option value="<?php echo $rows['id']; ?>">
<?php echo "$rows[coursecode]";
}}?>
</option>

this is the static code, how i can automate it so that options in select course will appear only after the selection of class