Javascript 根据表单输入从数据库检索数据并显示在同一页面上

Javascript 根据表单输入从数据库检索数据并显示在同一页面上,javascript,php,html,pdo,Javascript,Php,Html,Pdo,我有两个单选按钮和两个下拉列表。选择最后一个下拉列表后,我希望根据输入选择检索数据,然后显示在同一页面上?下面是我的代码。。。请指教,谢谢 <fieldset id="tradetype"> <span class="text_9">TRADE:</span> <span class="text_11"> <input type="radio" name="tradetype" required value="Buy"

我有两个单选按钮和两个下拉列表。选择最后一个下拉列表后,我希望根据输入选择检索数据,然后显示在同一页面上?下面是我的代码。。。请指教,谢谢

<fieldset id="tradetype">
    <span class="text_9">TRADE:</span>
    <span class="text_11">
    <input type="radio" name="tradetype" required value="Buy"/> Buy
    <input type="radio" name="tradetype" value="Sell"/> Sell </span>
</fieldset>
<fieldset id="Metal">
    <span class="text_9">METAL:</span>
    <span class="text_11">
    <input type="radio" name="metal" required value="Two"/> Two
    <input type="radio" name="metal" value="One"/> one </span>
</fieldset>
<fieldset id="Amount">
    <label><span class="text_9">AMOUNT:</span></label>
    <select name="amount">
        <option value="">Select</option>
        <?php include_once "selectamount.php"?>
    </select>
</fieldset>
<fieldset id="Date">
    <label><span class="text_9">DATE:</span></label>
    <select name="date" id="date" onchange="showData(this.Value)">
        <option value="">Select</option>
        <?php include_once "selectdate.php"?>
    </select>
</fieldset>
<input type="submit" name="formSubmit" value="Submit">
<div id="txtHint"></div>
PHP(使用PDO)



好的,问题是当我更改日期时没有显示

你需要提到什么是预期的结果,什么是不起作用的!更新!sry在添加代码后完全忘记了
        function showData(str) {
  if (str=="") {
    document.getElementById("txtHint").innerHTML="";
    return;
  } 
  if (window.XMLHttpRequest) {
    // code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
  } else { // code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  xmlhttp.onreadystatechange=function() {
    if (xmlhttp.readyState==4 && xmlhttp.status==200) {
      document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
  xmlhttp.open("GET","retrievepremordisc.php?q="+str,true);
  xmlhttp.send();
}
    <?php
include_once "connect.php";
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password); 

$form=$_POST;
$trade=$form['tradetype'];
$metal=$form['metal'];
$amount=$form['amount'];
$date=$form['date'];

$stmt = $conn->query("SELECT Discount FROM Contracts WHERE Trade=:trade AND Metal=:metal AND Amount=:amount AND ExpiryDate=:date");
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { 
   echo "<option value='" .  $row['Discount']. "'>" . $row['Discount'] . "</option>"; 
}
?>