当用户选择下拉列表值时,价格将根据数据库显示。我正在考虑代码。我希望任何人都可以在这里帮助我。
<form action="next.php" method="post">
<center>
<table>
用于显示表中的数据库行名的下拉列表 tabelmedicine
<tr><td width="116">Medicine name</td><td width="221">
<center>:
<select name="name" id="name">
<option>--- Choose Medicine ---</option>
与数据库连接
<?php
mysql_connect("localhost", "root", "");
mysql_select_db("arie");
$sql = mysql_query("SELECT * FROM tabelmedicine ORDER BY name ASC ");
if(mysql_num_rows($sql) != 0){
while($row = mysql_fetch_assoc($sql)){
echo '<option>'.$row['name'].'</option>';
}
}
?>
</select ></center>
</p></td></tr>
文本字段显示来自 tabelmedicine 行 priceperunit 的价格值
<tr><td><p>Price</p></td><td><p align="center">:<input type="text" name="price"
id="price"value="<?php echo ('priceperunit'); ?>" onClick="checkprice()">
</p></td></tr>
<script>
var select = document.getElementById('name');
var input = document.getElementById('price');
select.onchange = function()
{
input.value = select.value;
}
</script>