Jay Star
Jay Star

Reputation: 188

Pass entered value from one table to another table using javascript

I want to pass the entered value to table two when user I click add, the quantity will be added to the second table. When I click Add button quantity is displayed as an empty value. But not console this shows the entered quantity The quantity is of the same name and the quantityEntered is of the same name. When I inspect element I get the value entered on the...

"quantityEntered": <input type="text" id="CLT-K809S/SEE_quantity" name="quantityEntered" class="form-control" onkeypress="return isNumber(event)"  readonly=readonly value="1" />

...on every row of my new table.

Here is my code:

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="" />',

}]

Upvotes: 1

Views: 1146

Answers (1)

Jay Star
Jay Star

Reputation: 188

I managed to fix the problem I had by creating hidden input which I use to store my entered quantity and when user clicks add button,which is on the first and create my second table. I than get crap the entered value assign it to my hidden input.

<!-- 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"));
   });

Upvotes: 1

Related Questions