我想创建一个带有下拉列表的表单,该表单根据表单上的输入值更改其值。这是我一直在尝试但下拉列表仍然是空的。
我的表格
<form action="../action/subs/custompcorder.php/" method="post">
<div> <input id="rating" name="rating" onchange="loadComputers()"/> </div>
<select name="computer" id="computer"></select>
</div>
</form>
<script src="http://code.jquery.com/jquery-1.10.2.js" type="text/javascript"> </script>
<script src="./action/scripts/global.js" type="text/javascript"></script>
查询页面pcdrop2.php
<?php
include './action/db/connect6.php';
$rating = $_POST['rating'];
$myData=mysql_query("SELECT * FROM Product WHERE product.rate='$rating';");
while($record=mysql_fetch_array($myData)){
echo '<option value="'.$record['product_id'].'">'.$record['product'].'</option>';
}
?>
js函数从db中提取数据 global.js
function loadComputers() {
$val = $('#rating').html();
$.post('action/subs/pcdrop2.php', {
rating: $val
}, function (data) {
$('#computer').html(data);
});
}
答案 0 :(得分:0)
我认为这行代码:
$val = $('#rating').html();
实际应该是:
$val = $('#rating').val();