我想在用户点击添加时将输入的值传递给表2,数量将被添加到第二个表中。单击“添加”按钮时,数量显示为空值。但是没有控制台显示输入的数量
quantity
名称相同,quantityEntered
名称相同。当我检查元素时,我得到在...上输入的值
"quantityEntered": <input type="text" id="CLT-K809S/SEE_quantity" name="quantityEntered" class="form-control" onkeypress="return isNumber(event)" readonly=readonly value="1" />
...在我新桌子的每一行。
这是我的代码:
function saveEneteredQuantity() {
var quantity;
var quantityName;
var getEnteredQuantity;
var enteredQuatity;
var getIndex;
var textvalue = "";
quantity = document.getElementsByName("quantity").length;
quantityName = document.getElementsByName('quantity').value;
console.log("Count the lenght of the input textbox on the HO Stock : ", quantity);
document.getElementsByName("quantityEntered").value = quantityName;
getEnteredQuantity = quantity;
for (var i = 0; i < quantity; i++) {
textvalue = textvalue + document.getElementsByName("quantity").item(i).value;
}
$('[name="quantity"]').each(function(index) {
getIndex = $(this).val();
enteredQuatity = $('[name="quantity"]').eq(index).val();
});
quantity = textvalue;
alert("This was provided: ", quantity);
debugger;
console.log("Check the grapped quantity on table of Selected Line Items to Order : ", quantity);
if (quantity == '' || quantity == 0) {
alert("Quantity can not 0.\n Please enter quantity which is less than available quantity");
}
console.log("Entered Quantity: ", quantity);
}
var items = [{
"avalaibleQty": '<input type="text" id="CLT-C659S/SEE_avaliableQuantity" name="avaliableQuantity" class="form-control" readonly="readonly" value="1">',
"quantityEntered": '<input type="text" id="quantityEntered" name="quantityEntered" readonly="readonly" class="form-control" />',
"quantity": '<input type="text" id="quantity" name="quantity" class="form-control" onkeypress="return isNumber(event)" onblur="compareQuantity(this, 1)" required="required" value="" />',
}]
答案 0 :(得分:1)
我设法通过创建隐藏的输入来解决我遇到的问题,我用它来存储我输入的数量,当用户点击添加按钮时,这是第一个并创建我的第二个表。我得到的输入值将其分配给我隐藏的输入。
<!-- part Number and Quantity Entered -->
<input type="hidden"id="quantityList" name="quantityList" class="form-control" value="" />
var quantityList = [];
$(".addLineItem").on("click", function() {
debugger;
var items = [];
var row = $(this).closest("tr").clone();
var partNumber = $(this).closest('tr').find('td:eq(0)').find('input').val();
var quantity = $(this).closest('tr').find('td:eq(4)').find('input').val();
quantityList [quantityList.length]= [quantity];
document.getElementById("quantityList").value = quantityList;
debugger;
items.push(row);
row.appendTo($("#mySecondTable"));
});