Click here to Skip to main content
15,910,981 members
Please Sign up or sign in to vote.
1.43/5 (3 votes)
See more:
Hello, I need to make a multiplication of a div.class per a number (240). At the begging there's only one div.class but user can add new divs with the same class.

The problem is that the result of the multiplication does not change when the user adds or removes divs...

http://jsbin.com/tuguredu/1/edit

Can someone help me please.
Posted

First, change this:
$(document).ready(function() {
       $(".total").text($("div.person").length*240);
});

to:
function update(){
   $(".total").text($("div.person").length*240);
}

then insert update() to:
C#
$(document).ready(function(){
   var counter = 2;

   update();

   $("#addButton").click(function (){
      // other code
      counter++;

      update();

   });

   $("#removeButton").click(function () {
      // other code
      counter--;
      $("#TextBoxDiv" + counter).remove();

      update();
   });

   // other code

});
 
Share this answer
 
v3
From what I can see, you never tell it to update the total. The total is only calculated in document.ready() which is called once when the page loads. You need to put the totalling in its own function, and call that functionfrom the add/delete function.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900