dso15221 2018-10-03 10:23
浏览 67

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

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>
  • 写回答

1条回答 默认 最新

  • dongyupan4850 2018-10-03 12:00
    关注

    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

    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图