0

我正在尝试打印下拉选定的项目。我已经很好地展示了 dropdwon 列表菜单。但是当我选择一个选项时,它不会打印该选项。我已经尝试了很多方法。但是还没拿到!请帮助我,这是我的以下代码。

<form name="choose" method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">

<?php 
$query="SELECT id_cat,name FROM `fs01_metier_cat` ORDER BY `fs01_metier_cat`.`id_cat`";
$result = mysql_query($query);
?>

<?php
echo "<select name=category></option>";
while($nt=mysql_fetch_array($result)) {
    echo "<option value='".$nt['name']."'>".$nt['name']."</option>";
}
echo "</select>";
?>

<input type="submit" name="submit" value="save category" />
</form>

<?php
if($_GET){
   echo 'The year selected is'.$_GET['category'];
}
?>
4

2 回答 2

0
$_GET['category']

应该

$_POST['category']

javascript 示例:

<html>
 <head>
  <script type="text/javascript">
    window.onload = function() {
        var eSelect = document.getElementById('cat');
        eSelect.onchange = function() {

      document.getElementById("displaytext").innerHTML = "Selected Value: "+this.value;
      document.getElementById("displaytext").style.display= 'block';

        }
    }
  </script>
 </head>
 <body>
    <select id="cat" name="cat">
        <option value="x">X</option>
        <option value="y">Y</option>
        <option value="other">Other</option>
    </select>
    <div id="displaytext" style="display: none;" ></div>

</body>
</html>

​</p>

于 2012-08-08T01:08:04.393 回答
0

你的代码有问题,试试这个:

<form name="choose" method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">

<?php 
$query="SELECT id_cat,name FROM `fs01_metier_cat` ORDER BY `fs01_metier_cat`.`id_cat`";
$result = mysql_query($query);
?>

<select name=category>
<?php
while($nt=mysql_fetch_array($result)) {
    echo "<option value='".$nt['name']."'>".$nt['name']."</option>";
}
?>
</select>

<input type="submit" name="submit" value="save category" />
</form>

<?php
if($_GET){
   echo 'The year selected is'.$_GET['category'];
}
?>
于 2012-08-08T01:12:33.630 回答