简体   繁体   English

在选择选项中找不到值

[英]value not find in select option

I want, php find my value from select box but here don't find. 我想要,php从选择框中找到我的值,但在这里找不到。

I have html: 我有html:

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

And js: 和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);

And my php is: 而我的PHP是:

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

I see here, value is empty. 我在这里看到,值是空的。 What is wrong and how I fix this? 有什么问题,我该如何解决? In the end my html look like this: 最后,我的html看起来像这样:

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

Is your <select> placed inside <form method="post" action="your.php"> ? 您的<select>放置在<form method="post" action="your.php"> If you don't specify method, it will send the value in $_GET instead. 如果不指定方法,它将以$_GET发送值。 You could check Using $_POST to get select option value from HTML which is very similar. 您可以选中使用$ _POST从HTML获取选择选项值,这非常相似。

I'm not sure what you mean in your question.. maybe this seems like this case. 我不确定您在这个问题中是什么意思。 hope can fix your issue. 希望可以解决您的问题。

<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;
  }
?>

I FIND PROBLEM: document.getElementById("outputFormat").options.length = 0; 我发现问题: document.getElementById("outputFormat").options.length = 0; here is problem 这是问题

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

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