0

I've a script calculates my dynimic buy form. Everything works fine but when I add quantity input script takes only first value. I want to it takes every next value from "value" (each). I will be glad for help.

$(function() {
    $("#sumuj").click(function() {
        var add = 0;
        var add2 = 0;
        $(".netto").each(function() {add += Number($(this).val()) * $(".value").val();});
        $(".brutto").each(function() {add2 += Number($(this).val()) * $(".value").val();});
        add = add.toFixed(2);
        add2 = add2.toFixed(2);
    $("#price").val(add);
    $("#pricevat").val(add2);
    });
});

Done:

$(function() {
    $("#sumuj").click(function() {
        var add = 0;
        var add2 = 0;
        $(".netto").each(function() {add += Number($(this).val()) * Number($(this).parent().find('.value').val());});
        $(".brutto").each(function() {add += Number($(this).val()) * Number($(this).parent().find('.value').val());});
        add = add.toFixed(2);
        add2 = add2.toFixed(2);
    $("#price").val(add);
    $("#pricevat").val(add2);
    });
});

Thx for help/

1
  • 2
    jsfiddle and corresponding HTML would be helpful Commented May 7, 2013 at 12:42

1 Answer 1

1

Your script is incorrect : if you select all the value ( $(".value") ), and I believe you have different line of products, you will have strange equation (you multiply every value together ?? )

And please add a link of your page.

Sign up to request clarification or add additional context in comments.

4 Comments

I will glad for help with that script
Can you please paste the full page generated on jsfiddle ? We can't read easily your code. Here you sent us the php file not compiled, not very interesting ...
Maybe that question will be better: How get every next "value" class input? in jquery? $(".netto").each(function() {add += Number($(this).val()) * $(".[every-next]value").val();});
You have to adapt your HTML for simplify your JS. In your case, I would put something like : $(".line").each(function() {resultLine = parseFloat($('.price').val()) * parseFloat($(".quantity").val());})

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.