我有五个下拉列表,根据选择,显示更改为阻止。当值被回发时,问题就来了。下拉列表不显示值。这可能是因为默认情况下 javascript 在下拉列表中显示为 none。javascript 监听 onclick。这是javascripts的一部分:
function changeOptions() {
var form = window.document.getElementById("frm1");
var sv = window.document.getElementById("sv");
var sv2= window.document.getElementById("sv2");
var sv3 = window.document.getElementById("sv3");
var sv4= window.document.getElementById("sv4");
var sv5 = window.document.getElementById("sv5");
if (form.radioButton1.checked) {
sv2.style.display = "none";
sv3.style.display = "none";
sv4.style.display = "none";
sv5.style.display = "none";
sv.style.display = "block";
//sv.selectedIndex =0;
else if (form.radioButton5.checked) {
sv.style.display = "none";
sv2.style.display = "none";
sv3.style.display = "none";
sv4.style.display = "none";
sv5.style.display = "block";
sv5.selectedIndex = 0;
}
}
window.document.getElementById("radioButton5").onclick = changeOptions;
下拉菜单是从我的数据库中填充的。下面是代码。其中有五个 display:none 根据单击的单选按钮更改为阻止。
<select style="width:200px; **display:none**" name="pGroup" id="sv" >
<option value="Choose an Option" >Choose Product Group</option>
<?php
$selGroup = isset($_GET['pGroup'])?$_GET['pGroup']:"";
$sql="SELECT DISTINCT pGroup FROM cr39 WHERE ";
$sql.="HeadingNo = 3 ORDER BY pGroup ASC";
$result =mysql_query($sql);
while ($data=mysql_fetch_assoc($result)){
?>
<option <?php if($data['pGroup'] == $selGroup) echo 'selected="selected"'; ?> value ="<?php echo $data['pGroup'] ?>" ><?php echo $data['pGroup'] ?></option>
<?php } ?>
</select>
. . . .
<select style="width:200px; **display:none**" name="pGroup5" id="sv5">
<option value="Choose an Option" >Choose Product Group</option>
<?php
$selGroup = isset($_GET['pGroup5'])?$_GET['pGroup5']:"";
$sql="SELECT DISTINCT pGroup FROM cr39 WHERE ";
$sql.="HeadingNo = 7 ORDER BY pGroup ASC";
$result =mysql_query($sql);
while ($data=mysql_fetch_assoc($result)){
?>
<option <?php if($data['pGroup'] == $selGroup) echo 'selected="selected"'; ?> value ="<?php echo $data['pGroup'] ?>" ><?php echo $data['pGroup'] ?></option>
<?php } ?>
</select>
我是这方面的新手,希望获得有关如何在我的回发下拉列表中保留价值的帮助。