You are viewing limited content. For full access, please sign in.

Question

Question

How to trigger a calculation based on table row deletion in Forms

asked on January 26, 2015

I have a form with a table in which amounts are entered in the last column. Users can add rows to enter multiple amounts. As they enter amounts, the total is calculated in a field that's below the table. That works fine. However, if the user deletes one of the rows of the table, the total amount isn't recalculated unless the user clicks in any two remaining cells in the table.

Can anyone tell me what I'm missing?

 

Thanks!

0 0

Replies

replied on February 5, 2015

Hi There

 

I would also like to know what type of trigger and how it would reference the delete button.

 

Thanks

 

0 0
replied on February 5, 2015

Hi guys,

The challenge here is that there seems to be no event that can monitor a removal of a row from the table. The Change event will only monitor input/select/textarea elements of a table.

Using setInterval, you can continuously monitor changes made. Be sure to add it within your document.ready function, so that it loads with your form. This will monitor your table you specify for any changes in it's html structure.

  

var html;
setInterval(function() {
    var table = $('.tableCSSname');
    if($('.tableCSSname').html() != html){
        sumtotal();
        html = $('.tableCSSname').html();
    }
}, 500);

Regards,

Sheldon

0 0
replied on April 9, 2015

You can also accomplish this by adding another trigger to your JavaScript. This line will trigger calculations anytime there is a click in the table (this includes adding or removing rows). 

$(".tableClass").on("click", tableFunction);
0 0
replied on January 5, 2016 Show version history

This took me a little while to figure out, but the following code should do the trick:

$(document).on('click', '.form-del-field', function() {

      console.log('Row Deleted!');

});

I've tested it in Chrome and IE, and it works great! This should get around the need to set up a poll.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.