簡體   English   中英

在選擇選項中找不到值

[英]value not find in select option

我想要,php從選擇框中找到我的值,但在這里找不到。

我有html:

<select name="outputFormat" id="outputFormat">
</select> 

和js:

document.getElementById("outputFormat").options.length = 0;
var obj=document.getElementById("outputFormat");
var opt = document.createElement('option');
opt.value = "DOC";
opt.innerHTML = "DOC";
obj.appendChild(opt);

而我的PHP是:

$outputFormat = $_POST['outputFormat'];
switch ($outputFormat) {
case 'DOC':
echo "find";  //here is not
break;

我在這里看到,值是空的。 有什么問題,我該如何解決? 最后,我的html看起來像這樣:

<select name="outputFormat" id="outputFormat">
<option value="DOC">DOC</option>
</select>

您的<select>放置在<form method="post" action="your.php"> 如果不指定方法,它將以$_GET發送值。 您可以選中使用$ _POST從HTML獲取選擇選項值,這非常相似。

我不確定您在這個問題中是什么意思。 希望可以解決您的問題。

<script type="text/javascript">
<!--
function addValue() {
    var obj=document.getElementById("outputFormat");
    var opt = document.createElement('option');
    opt.value = "DOC";
    opt.innerHTML = "DOC";
    obj.appendChild(opt);
}
//-->
</script>



<form method="POST" name="test">
<select name="outputFormat" id="outputFormat">
</select>
<input type="submit" name="submit" value="submit" onclick="addValue();">
</form>
<?php
  $outputFormat = $_POST['outputFormat'];
  switch ($outputFormat) {
    case 'DOC':
    echo "find";  //here is not
    break;
  }
?>

我發現問題: document.getElementById("outputFormat").options.length = 0; 這是問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM