Jquery或代码更新Infusionsoft订单上的订单总额

kx5bkwkv  于 2023-10-17  发布在  jQuery
关注(0)|答案(1)|浏览(94)

我试图动态更新订单总额,因为我有两个数量领域的用户将更新,然后价格将增加取决于他们设置的数量。
我找不到任何代码,将动态更新的订单总额通过自定义代码

nwwlzxa7

nwwlzxa71#

您可以使用JavaScript(包括jQuery)来监听数量字段中的变化,并相应地计算总数。下面是一个示例代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
    <!-- Quantity Fields -->
    <label for="quantity1">Quantity 1:</label>
    <input type="number" id="quantity1" value="0">
    <br>
    <label for="quantity2">Quantity 2:</label>
    <input type="number" id="quantity2" value="0">
    <br>
    <!-- Display Total -->
    <p>Total: $<span id="total">0.00</span></p>

    <script>
        // Function to update the total based on quantity fields
        function updateTotal() {
            // Get the values of quantity fields
            var quantity1 = parseInt($('#quantity1').val());
            var quantity2 = parseInt($('#quantity2').val());
            
            // Calculate the total based on your pricing logic
            var total = (quantity1 * 10) + (quantity2 * 15); // Adjust pricing as needed
            
            // Update the total display
            $('#total').text(total.toFixed(2));
        }

        // Attach change event listeners to quantity fields
        $('#quantity1, #quantity2').on('change', function() {
            updateTotal();
        });

        // Initial total update
        updateTotal();
    </script>
</body>
</html>

相关问题