简体   繁体   English

为什么我的动态下拉列表不起作用?

[英]Why is my dynamic dropdown list not working?

The drop down list is suppose to fetch records from a column in another table but currently there are no records appearing. 假定下拉列表是从另一个表的列中获取记录,但是当前没有记录出现。 Also, i would need an option in the drop down list that says "others" for the users to key in if they cannot find what they want in the list. 另外,如果用户在列表中找不到想要的内容,我将需要在下拉列表中显示一个“其他”选项,以便用户键入。 Here are my codes: 这是我的代码:

<script type="text/javascript">
    function showfield(name){
    if(name=='Other')document.getElementById('div1').innerHTML='Please Specify: <input type="text" name="other" />';
    else document.getElementById('div1').innerHTML='';
    }
    </script>   
<label for="issue_type">Issue Type</label>
<?php 
include ("../db/dbConn.php"); 
$sql = "SELECT issue_type FROM issue where deleted =0"; 
$result=mysql_query($sql);
echo '<select class ="form-control" type="text" name="issue_type" id="issue_type" onchange="showfield(this.options[this.selectedIndex].value)" >';
 while ($row = mysql_fetch_array($result)) 
{ 
 echo "<option value='".$row['issue_type']."'>".$row['issue_type']."      </option>"; 
    } 
   echo "</select>";

?>
<div id="div1"></div>

assign html section to a variable, then echo it. 将html部分分配给变量,然后将其回显。 try 尝试

<script type="text/javascript">
function showfield(name){
if(name=='Other')document.getElementById('div1').innerHTML='Please Specify: <input type="text" name="other" />';
else document.getElementById('div1').innerHTML='';
}
</script>   
<label for="issue_type">Issue Type</label>
<?php 
include ("../db/dbConn.php"); 
$sql = "SELECT issue_type FROM issue where deleted =0"; 
$result=mysql_query($sql);

$htm = '';
$htm .='<select class ="form-control" type="text" name="issue_type" id="issue_type" onchange="showfield(this.options[this.selectedIndex].value)" >';
while ($row = mysql_fetch_array($result)) 
{ 
$htm .="<option value='".$row['issue_type']."'>".$row['issue_type']."      </option>"; 
} 
$htm .= "<option value='Other'>Other</option>"; // add other option
$htm .="</select>";
echo $htm;
?>
<div id="div1"></div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM