2009-11-15 66 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