[英]Form Inputs updated via JS don't get submitted
The invoice input values which hold the totals of invoice line items that get updated via JS return a NULL value when they are submitted. 提交通过JS更新的包含发票行项目总数的发票输入值在提交时返回NULL值。
<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" />
The JS 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();
});
}
);
});
I originally had the inputs set as disabled however I have changed them to readonly because disabled fields can't be submitted. 我最初将输入设置为禁用,但是由于无法提交禁用字段,因此将它们更改为只读。
What am i missing? 我想念什么?
Thanks in advance. 提前致谢。
You haven't set a name
-attribute on your <input />
s, so PHP can't access their values, and returns nothing when you look for $_POST['product-tax']
. 您没有在<input />
上设置name
-attribute,因此PHP无法访问它们的值,并且在寻找$_POST['product-tax']
时不返回任何内容。 If you have set error_reporting
to E_ALL
, you should see a notice telling you you are trying to access an undefined index on the $_POST
array. 如果将error_reporting
设置为E_ALL
,则应该看到一条通知,告知您正在尝试访问$_POST
数组上的未定义索引。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.