douzhi7070 2019-03-18 07:30 采纳率: 0%
浏览 157

Javascripts中的总价格和数量

Hi guys am trying to get the Total price and quantity of each items. So, i have a fixed price of $20. the price comes out fine but its not counting the quantity of each items....

HTML code

HTML-Continous

This is the code for Total Quantity and this works fine in an input field.

function changeval() {
    $total = parseInt($("#A1").val()) + parseInt($("#B1").val()) + parseInt($("#C1").val()) + parseInt($("#D1").val()) + parseInt($("#E1").val());

    $('.A').val($("#A1").val());
    $('.B').val($("#B1").val());
    $('.C').val($("#C1").val());
    $('.D').val($("#D1").val());
    $('.E').val($("#E1").val());
    $('.total').val($total);
}

HERE IS THE PROBLEM when i add this code, the Price comes out good but the quantity no longer SHOWS.

function changeval() {
    $price = parseInt($("#A1").val() * 20) + parseInt($("#B1").val() * 20) + parseInt($("#C1").val() * 20) + parseInt($("#D1").val()* 20) + parseInt($("#E1").val()* 20);

    $('.A').val($("#A1").val());
    $('.B').val($("#B1").val());
    $('.C').val($("#C1").val());
    $('.D').val($("#D1").val());
    $('.E').val($("#E1").val());
    $('.price').val($price);
}

so i want to have something like this

PRICE = 20 QUANTITY= 1 PRICE = 40 QUANTITY= 2 '' '' since i have 20 as a fixed price. Any help will be appreciated.

  • 写回答

1条回答 默认 最新

  • dqg2269 2019-03-18 07:59
    关注

    The reason is you are using same function name for all onchange function. i.e, for updating price and total you are using the same changeval1() function.

    Try changing name of the function. Both function has same name. One function updates total and another updates price. So when both function has same name, both price and total gets updated.

    评论

报告相同问题?