我试图在下拉列表中选择一个项目后对价格进行求和,但它只显示 NaN。下拉列表的值是从 MySQL 数据库检索的
<?php
//database connection here
?>
<table border=" 1">
<thead>
<tr>
<th>Component</th>
<th>Item Name</th>
<th>Price </th>
</tr>
</thead>
<tbody>
<tr>
<td>CPU</td>
<td>
<?php
//Retrieving CPU table
$query = $conn->query("SELECT * FROM cpu");
echo '<select onChange = parseFloat($("#cpuprice").val($(this).find("option:selected").attr("cpuprice")))>';
echo "<option>---select your CPU---</option>";
while ($obj = $query->fetch_object()) {
echo '<option cpuprice = "' . $obj->price . '" >' . $obj->cpuname . '</option>';
}
echo '</select>';
?>
</td>
<td>
<output class="form-control prc" id="cpuprice" disabled value="">
</td>
</tr>
</tbody>
<tbody>
<tr>
<td>GPU</td>
<td>
<?php
//Retrieving GPU table
$query = $conn->query("SELECT * FROM gpu");
echo '<select onChange = parseFloat($("#tpuprice").val($(this).find("option:selected").attr("gpuprice")))>';
echo "<option>---select your GPU---</option>";
while ($obj = $query->fetch_object()) {
echo '<option gpuprice = "' . $obj->price . '" >' . $obj->gpuname . '</option>';
}
echo '</select>';
?>
</td>
<td>
<output class="form-control prc" id="tpuprice" disabled value="">
</td>
</tr>
</tbody>
</table>
https://i.stack.imgur.com/zPdnK.png
慕容708150
相关分类