1

I want, php find my value from select box but here don't find.

I have html:

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

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

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

<select name="outputFormat" id="outputFormat">
<option value="DOC">DOC</option>
</select>
Nejc Galof
  • 2,538
  • 3
  • 31
  • 70

3 Answers3

0

Is your <select> placed inside <form method="post" action="your.php">? If you don't specify method, it will send the value in $_GET instead. You could check Using $_POST to get select option value from HTML which is very similar.

Community
  • 1
  • 1
Christoffer
  • 2,125
  • 15
  • 21
0

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;
  }
?>
willcooler
  • 15
  • 1
  • 7
0

I FIND PROBLEM: document.getElementById("outputFormat").options.length = 0; here is problem

Nejc Galof
  • 2,538
  • 3
  • 31
  • 70