2009-11-15 73 views
0

通過JS更新的包含發票行項目總計的發票輸入值在提交時返回NULL值。通過JS更新的表單輸入未提交

<span class="sublabel">Subtotal</span><input type="text" class="total-box" id="product-subtotal" readonly="true" /> 
<span class="sublabel">Tax</span><input type="text" class="total-box" id="product-tax" readonly="true" /> 
<span class="sublabel">Total</span><input type="text" class="total-box" id="order-total" readonly="true" /> 

的JS

function calcProdSubTotal() { 

    var prodSubTotal = 0; 

    $(".row-total-input").each(function(){ 

     var valString = $(this).val() || 0; 

     prodSubTotal += parseInt(valString); 

    }); 

    $("#product-subtotal").val(prodSubTotal); 

    }; 

function calcTaxTotal() { 

    var taxTotal = 0; 
    //var taxAmount = 10; 
    var taxAmount = $("#salesTaxAmount").val() || 0; 

    var productSubtotal = $("#product-subtotal").val() || 0; 

    var taxTotal = parseInt(productSubtotal) * parseInt(taxAmount)/100; 
    var taxTotalNice = taxTotal; 
    $("#product-tax").val(taxTotalNice); 

}; 

function calcOrderTotal() { 

    var orderTotal = 0; 

    var productSubtotal = $("#product-subtotal").val() || 0; 
    var productTax = $("#product-tax").val() || 0; 

    var orderTotal = parseInt(productSubtotal) + parseInt(productTax); 
    var orderTotalNice = "$" + orderTotal; 

    $("#order-total").val(orderTotalNice); 

}; 



$(function(){ 
    $('.row-total-input').each(
     function(intIndex){ 
      $('.invAmount').livequery('blur', function() { 
        var $this = $(this); 
        var amount = $this.val(); 

        var qty = $this.parent().find('.invQty').val(); 

        if ((IsNumeric(amount)) && (amount != '')) {   
         var rowTotal = qty * amount; 
         $this.css("background-color", "white").parent().find(".row-total-input").val(rowTotal); 
        } else {   
         $this.css("background-color", "#ffdcdc");      
        };        
        calcProdSubTotal(); 
        calcTaxTotal() 
        calcOrderTotal(); 
      }); 
     } 
    ); 
}); 

我原本的輸入設置爲禁用,但是我已經改變了他們爲只讀,因爲殘疾字段不能提交。

我在想什麼?

在此先感謝。

+0

小小的東西,對於真正的問題沒有實現:它應該是readonly="readonly"而不是readonly="true"。 – 2009-11-15 10:52:39

+0

好的抱歉。我會記住這一點 – Tristan 2009-11-16 04:32:57

回答

3

您還沒有在<input />上設置name屬性,所以PHP無法訪問它們的值,並且在您尋找$_POST['product-tax']時不返回任何內容。如果您將error_reporting設置爲E_ALL,您應該會看到一條通知,告知您正試圖訪問$_POST陣列上未定義的索引。

+0

良好的通話! <評論長度填充文本> – 2009-11-15 11:14:04

+0

哈哈和我一直在盯着那麼久試圖解決它,謝謝 – Tristan 2009-11-16 04:33:27