我有两个下拉列表,如果一个值选择另一个从数据库加载相同的值,则一个依赖于另一个。例如,如果我选择一个国家,其他加载该国家的相同城市。
<select name="A" class="input_text" id="A">
<?php
include 'config/config.php';
$sql="SELECT * FROM department ORDER BY Dept ASC";
$result=mysql_query($sql);$options="";
while ($row=mysql_fetch_array($result)){
$did=$row["DeptCode"];
$depts=$row["Dept"];
$options.="<OPTION value='$did'>".$depts;}?>
<option value="0">Select...</option>
<?php echo $options; ?>'
</option>
</select>
<select name="B" class="input_text" id="B">
<?php
include 'config/config.php';
$sql="SELECT * FROM department WHERE DeptCode=$dpttitle";
$result=mysql_query($sql);$options="";
while ($row=mysql_fetch_array($result)){
$did=$row["DeptCode"];
$depts=$row["Dept"];
$options.="<OPTION value='$did'>".$depts;}?>
<option value="0">Select...</option>
<?php echo $options; ?>
</option>
</select>
<script type="text/javascript">
A.onblur = function() {
B.value = this.value;};
</script>