我正在努力开发在线报价表。我正在尝试根据是否选中复选框来更改价格。
行为应该是: 在初始页面加载时 - 标准(来自 mysql - 变量)价格 勾选复选框时 - 将 20 美元(来自 mysql )添加到价格 取消勾选复选框时 - 返回标准可变价格
我目前的行为是:在初始页面加载时 - 标准(来自 mysql - 变量)价格当勾选复选框时 - 20 美元(来自 mysql)但不添加到原始价格当复选框未勾选时 - NaN
我可以确认价格在 mysql 中存储为整数,例如 292 任何帮助将不胜感激。
下面的代码:html页面中的php
<?php
$table = $_GET['bintype'];
$pcode = $_GET['tags'];
include 'connect.php';
$result=mysqli_query($con,"SELECT * FROM $table WHERE short='$pcode'");
$row_cnt = mysqli_num_rows($result);
if($row_cnt == 0)
{
PRINT "<p align='middle'>No go</p>";
}
else
while($row=mysqli_fetch_array($result))
{
$b = number_format($row['barrow'], 2) AND "<div id='barrowid'>";
$c = number_format($row['2m3 General'], 2) AND "<div id='total_price'>";
$d = $row['2m3 General'] AND "<div id='total_number'>";
echo "<form id='checkboxval'><input type='checkbox' id='checkit' name='menu1'
value=".$b.">
</input> <div id='total'>Total:$".$d."</div>
</form>";
}
mysqli_close($con);
?>
javascript
var checkbox = document.getElementById("checkit");
checkbox.onclick = function () {
var subtotalField = document.getElementById("total_price");
var checkboxes = document.forms["checkboxval"].getElementsByTagName("input");
var subtotal = document.getElementById("total_price");
var total = document.getElementById("total_price");
for (var i = 0, length = checkboxes.length; i < length; i++) {
if (checkboxes[i].checked) {
var newSubtotal = parseInt(subtotal.innerHTML) + parseInt(checkboxes[i].value);
subtotal.innerHTML = newSubtotal;
}
}
total = (parseFloat(subtotal));
document.getElementById("total").innerHTML = "Total:$" + total;
};