单击另一个输入时,值会发生变化

时间:2017-12-23 21:53:48

标签: javascript php html

onkeyup关于输入并输入一个新值,总价值应该用价格更新,但是如果我将2的值放在第一个输入中则总计更改为50这是正确的,但如果我在第二个输入中键入一个值,则值将返回到42

我忘了这个问题与数据库的输入有关,请访问网站http://naturalflame.altervista.org/ login guest@naturalflame.com传递客人

错误发生在审核和自定义页面

function UpdatePrice(id,price){
            var amount = document.getElementById("amount" + id).value;
            var total = document.getElementById("total").value;
            var totalText = document.getElementById("totalText");
            
            total -= price;
            total += price * amount;
            console.log(total);
            
            totalText.innerHTML = "TOTAL: $" + total;
        }
<table> 
    	    <tr> 
    	        <th>Order Details</th>  
    	        <th>Price</th> 
                <th>Quantity</th> 
    	    </tr>
            <?
            	$sql = "SELECT * FROM cart WHERE email='$email'";
                $query = mysql_query($sql);
                $priceTotal = 0;
                while($row = mysql_fetch_object($query)){
                	$id = $row->id;
                	$detail = $row->details;
                    $price = $row->price;
                    
                    $priceTotal = $priceTotal + $price;
                    
                    $details = explode("|",$detail);
                    
                    $size = $details[0] . "ml";
                    $flavor = $details[1];
                    $blend = $details[2];
                    echo "
                    	<tr>
                    		<td>$size,$flavor,$blend</td>
                            <td>$$price</td>
                            <input type='number' class='hidden' id='price$id' value='$price'>
                            <td><input type='number' id='amount$id' value='1' onclick='UpdatePrice($id,$price)'></td>
                        </tr>
                    ";
                }
                echo "
                	<input type='number' class='hidden' id='total' value='$priceTotal'>
                	<span id='totalText'>TOTAL: $$priceTotal</span>
                    <button class='btn btn-info' onclick='Checkout()'>Checkout</button>
                ";
			?>
    	</table>
        </div><!--end main-->

0 个答案:

没有答案