购物车数量变化 价格随之变化 如何存入数据库
我在做一个购物车
数量可以变化 价格也随着变化
购物车下面是总价格
本人对js不是很熟悉 所以从网上找了段代码
<td> <input size= "3 " name= "count " value= " <%=number%> " id= "count " type= "text " onChange= "doSum(); "> </td>
<input name= "price " id= "price " type= "hidden " value= " <%=price%> ">
<td> <input size= "3 " name= "sum " id= "sum " value= " <%=price%> " type= "text " readonly> </td>
JS:
<script language= "JavaScript ">
function doSum(){
document.all[ 'sum '].value = document.all[ 'price '].value * document.all[ 'count '].value;
}
</script>
可是问题也随之出现 一个物品的时候 还可以实现 要是购物车有都个产品 就不能了, 而且我有一张购物车的表 但是这数量的变化 和总价格的变化 如果存入到数据库中 .
谢谢各位
------解决方案--------------------不好意思 有些错误
<table> <tr>
<td> <input size= "3 " name= "count " value= " <%=number%> " id= "count " type= "text " onChange= "doSum(); "> </td>
<input name= "count_old " id= "count_old " type= "hidden " value= " <%=number%> ">
<input name= "price " id= "price " type= "hidden " value= " <%=price%> ">
<td> <input size= "3 " name= "sum " id= "sum " value= " <%=price%> " type= "text " readonly> </td>
<input name= "sum_old " id= "sum_old " type= "hidden " value= " <%=price%> ">
</tr> </table>
<script language= "JavaScript ">
function doSum(){
document.all[ 'sum '].value = Number(document.all[ 'price '].value) * Number(document.all[ 'count '].value);
}
</script>