如何总结textboxA总结文本框(从数据库中值)和HTML文本框(手动输入)(接到数据库值)* textboxB(手动键入的值)如何在PHP
我想做= 价格*数量 - 盘=总
,其中从数据库中生成价格的价值只想计算,
这里是代码
<?php
$con = mysqli_connect('localhost', 'root', '', 'a.karat');
if(isset($_POST['product_id']))
{
$prno=$_POST['prno'];
$i=1;
$sql = mysqli_query($con,"select * from detail_pr where prNo='$prno'");
while ($r = mysqli_fetch_array($sql)) {
echo
'<tr>
<td><input type="checkbox" name="check[]" id="check'.$i.'" value="'.$i.'"></td>
<td><label for="productCode"></label>
<input type="text" name="productCode'.$i.'" id="productCode'.$i.'" readonly value="'.$r["productCode"].'" ></td>
<td><label for="productName"></label>
<input type="text" name="productName'.$i.'" id="productName'.$i.'" readonly value="'.$r["productName"].'"></td>
<td><label for="qty"></label>
<input type="text" name="price'.$i.'" id="price'.$i.'" readonly value="'.$r["qty"].'" ></td>
<td><input type="text" name="qty'.$i.'" id="qty'.$i.'" ></td>
<td><input type="text" name="disc'.$i.'" id="disc'.$i.'" ></td>
<td><input type="text" name="total'.$i.'" id="total'.$i.'" ></td>
</tr>';
$i++;
}
}
?>
<script type="text/javascript">
function calculate(id){
var quantity = document.getElementById('qty'+id).value;
var price = document.getElementById('price'+id).value;
var sum = parseInt(quantity,10)*parseInt(price,10);
document.getElementById('total'+id).value = sum;
}
</script>
我想知道怎么做
价格*数量 - 盘=总
谁能帮助我?
感谢
代码给你一些错误? –
没有结果,也没有错误,我不知道是我的代码是否有效 – Alra
@Alra是否正确调用了calculate(id)函数? –