选择一个选择框会使其他选择框空白

I have two select boxes in which 1st one is having names of Units and second one has names of chapters. My problem is whenever I am selecting option in the first select box option i.e. Units, my second drop down i.e. Chapters becomes empty. While doing reverse, i.e. if I am selecting the chapters first and then Unit, again the chapters becomes blank. What could be the possible reason behind it? Here is my code,

 function selectBoxsearch($tableName, $field1, $field2, $value)
{   

    echo "<option value=''>--Select--</option>";
    $sq=mysql_query("SELECT *  FROM $tableName where status=1 order by id ASC");
    while($row=mysql_fetch_array($sq))
        {
            if($value==$row[$field1])
            {

        echo "<option value='$row[$field1]' selected='selected'; >$row[$field2]</option>";  
            }
            else
            {

        echo "<option value='$row[$field1]' >$row[$field2]</option>";   
            }
        }                   

}  



 <div class="form-group">
 <div class="col-md-12">
 <div class="col-md-3">
 <label for="username" class="control-label">Select Unit:</label>
</div>
<div class="col-md-9">
<select name="unit_id" class="form-control"  required="" id="unit_id">
 <?php $fnc->selectBoxsearch("tbl_question_module","id","title", $unit_id) ; ?>
</select>
</div>
 </div>
 </div>
 <div class="form-group">
 <div class="col-md-12">
 <div class="col-md-3">
<label for="username" class="control-label">Select Chapter:</label>
   </div>
  <div class="col-md-9">
  <select name="chapter" class="form-control" required id="chapter_id" >   

<option value="">Select</option>                  
<?php 

$sql = mysql_query("SELECT id, title FROM tbl_studymaterials where status =1 ");
while ($row = mysql_fetch_assoc($sql)){   
$chapter = $row['title'];

echo "<option value=" . $row['id'] . ">" . $chapter . "</option>";
    }

    ?>
</select>
</div>
</div>
</div>

Finally got the solution. I was passing wrong id to the Chapter label . So it should be id= chapter but not id= chapter_id. Thanks