0

I have a group of select boxes with different number values that are added together to produce a sum.

Instead of having to refresh the page every time I want the new value, how can the Jquery be altered so that the new selected values are remembered in the form, and the new sum is computed when the values are changed?

You can see what I'm trying to do here: http://jsfiddle.net/beehive/Za42G/3/

var combined = 0;
$("select").each(function() {
    combined += parseInt($(this).val());
});

$("#sum").html(combined);

$("#sum").change();

1 Answer 1

2

One possible way:

$("select").change(function() {
    var combined = 0;
    $("select").each(function() {
        combined += parseInt(this.value, 10);
    });
    $("#sum").html(combined);
}).trigger("change");​

DEMO: http://jsfiddle.net/Za42G/4/

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

Comments

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.