回发的回声值

时间:2012-09-13 11:46:29

标签: php javascript mysql html

我有五个下拉列表,根据选择显示更改为阻止。 回发值时会出现问题。下拉列表不显示值。这可能是因为javascript默认情况下显示为无下拉列表。 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;

从我的数据库填充下拉菜单。下面是代码。其中有五个显示:根据单击的单选按钮,无阻止更改。

   <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>

我是这方面的新手,希望能帮助我保留dropdownon回发的价值。

1 个答案:

答案 0 :(得分:0)

根据上面的评论,需要查看更准确的代码,但这里有一个伪版本,您可以调整;

<body 
<?PHP if(isset($_GET['selectedGroupId'];)){ ?>
    onload='window.document.getElementById("radioButton<?PHP echo $_GET['selectedGroupId']; ?>").click()'
<?PHP } ?>
>

$_GET['selectedGroupId']替换为您的fieldname / id

看看是否能让你走上正轨