JQuery adding multiple text field values

I have a new task, and I'm not sure what is the best way to approach it using jQuery.

Basically, the client wants “x” the number of text fields (for the number), each of which has a plus / minus icon / icon to the side of it, and with each click on each of them all relative fields are updated.

eg. (if there were 3 options on the page)

qty [0] + -
qty [0] + -
qty [0] + -

The total number of all of the above [0]

I use jQuery a lot, but I'm not sure where to start with this.

Any advice would be highly appreciated.

Adi.

+3
source share
1 answer

CSS , , , :

$('input.qty').change(function() {       
    // Loop through all input and re-calculate the total
    var total = 0;
    $('input.qty').each(function(){
        total += parseInt(this.value);
    });

    // Update the total
    $('#total').val(total);
);

.

  • + -. , / .
  • parseInt int. , .
+6

Source: https://habr.com/ru/post/1759869/


All Articles