当用户选择下拉列表值时,价格将根据数据库显示。我很想代码,希望有人在这里为我提供帮助。
<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>
文本字段,以显示来自禁忌医学行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>
这应该做。只要确保$row['price']
是正确的数据库字段密钥
<form action="insertout.php" method="post">
<center>
<table>
<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 value="'.$row['price'].'">'.$row['name'].'</option>';
}
}
?>
</select >
</center>
</p>
</td>
</tr>
<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>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句