我正在尝试使用 ajax 来更新Price
当用户选择size
它时,它将使用 pid 从数据库中获取价格。
谢谢
我的尺码表是这样的
pid psize pprice ssize sprice
1 12 25 12 30
2 14 30 14 40
3 16 35 16 45
4 18 45
形式
<form id="add" name="checkout" method="Post" action="checkout.php">
<table>
<tr>
<td width="160">Price:</td>
<td> </td> <!-- the price goes here and will change user
select from the option by default it should be what pid 1 psize is -->
</tr>
下面是我如何设置 psize 这个选项
<tr>
<td width="160">sizes*:</td>
<td>
<select name="length" id="length" class="small">
<?php
dbconnect();
$stmt = $conn->prepare("SELECT pid,psize FROM size");
$stmt->execute();
$i = 0;
foreach( $stmt->fetchAll(PDO::FETCH_ASSOC) as $row )
{
if ($i == 0)
{
echo '<option',fillSelect('psize',$row['pid'],'',true),' value="'.$row['pid'].'">'.$row['psize'].'</option>';
}
else
{
echo '<option',fillSelect('psize',$row['pid']),' value="'.$row['pid'].'">'.$row['psize'].'</option>';
}
$i++;
}
?>
</select>
</table>
<input type="hidden" name="pid" id="pid" value="<?php echo $pid; ?>" />
<input type="Submit" name="button" id="button" value="Add"/>
</form>