JavaScript Adding to a value declared in another function

It is hard to explain, you can see a DEMO HERE

I have a products table that dynamically creates/deletes new lines of products. I also have a totals table that totals up the totals of each line together.

In that totals box, I have a travel box I want to add to the grand total, but the issue I am having is the travel input is outside the table that is totaling all the values. I can replace the total with a new total, but I can not seem to call the sub total, add the travel and output a grand total.

HTML

<table class="order-details">
    <tbody>
    <tr>
        <td><input type="text" value="" name="" placeholder="Work Description" class="wei-add-field description 1"/></td>
        <td><input type="text" value="" name="" placeholder="QTY" class="wei-add-field quantity 1" /></td>
        <td><input type="text" value="" name="" placeholder="$0.00" class="wei-add-field unit-price 1"/></td>
        <td><input type="text" value="" name="" placeholder="$0.00" class="wei-add-field price-total 1" id=""/></td>
        <td> </td>
    </tr>
    </tbody>
</table>

<div class="wei-add-service"><a target='_blank' href="#" class="button-secondary wei-add-service-button">Add Item</a></div>

<table class="wei-add-totals">
    <tr>
        <td width="50%">Sub Total</td>
        <td width="50%" class="wie-add-subtotal"> </td>
    </tr>

    <tr class="alternate travel">
        <td>Travel</td>
        <td><input type="text" value="" placeholder="0.00" class="wei-add-field travel" /></td>
    </tr>
    <tr>
        <td>Taxes</td>
        <td><input type="text" value="" placeholder="0.00" class="wei-add-field wie-total-taxes" id="wei-disabled" disabled/> </td>
    </tr>
    <tr class="alternate total">
        <td>Total</td>
        <td><input type="text" value="" placeholder="0.00" class="wei-add-field wie-grand-total" id="wei-disabled" disabled/></td>
    </tr>
</table>

Javascript

var counter = 1;
var testArray =  [ 2,3,4,5];

jQuery('a.wei-add-service-button').click(function(event){
    event.preventDefault();
    counter++;
    var newRow = jQuery('<tr><td><input type="text" class="wei-add-field description ' + counter + '"/></td><td><input type="text" class="wei-add-field quantity ' + counter + '" /></td><td><input type="text" class="wei-add-field unit-price ' + counter + '"/></td><td><input type="text" value="" name="" placeholder="$0.00" class="wei-add-field price-total ' + counter + '" id=""/></td><td><a target='_blank' href="#">X</a></td></tr>');
    jQuery('table.order-details').append(newRow);
});


jQuery('table.order-details').on('click','tr a',function(e){
    e.preventDefault();
    var table = $(this).closest('table');
    jQuery(this).parents('tr').remove();
    reCalculate.call( table );
});


jQuery('table.order-details').on("keyup", "tr", reCalculate);

function reCalculate() {
    var grandTotal = 0;
    jQuery(this).closest('table').find('tr').each(function() {
        var row = jQuery(this);
        var value = +jQuery( ".unit-price", row ).val();
        var value2 = +jQuery( ".quantity", row ).val();
        var total = value * value2;
        grandTotal += total;
        jQuery( ".wei-add-field.price-total", row ).val( '$' + total.toFixed(2) );
    });
    jQuery(".wie-add-subtotal").text( '$' + grandTotal.toFixed(2));
}
Answer:1

I have a button. onClick the button fires a JS function. In this function on the very first line of code I change the button's HTML using jQuery. Then the function takes a couple seconds. The button ...

I have a button. onClick the button fires a JS function. In this function on the very first line of code I change the button's HTML using jQuery. Then the function takes a couple seconds. The button ...

  1. canvas
  2. canada
  3. cancelled
  4. canceled vs cancelled
  5. canada goose
  6. cancun flights
  7. cane corso
  8. canes
  9. canadian prime minister
  10. canker sore
  11. candy
  12. cancer
  13. cancun
  14. canon
  15. canvas prints
  16. cancer sign
  17. candace owens
  18. canada news
  19. candytopia
  20. canlis

I have successfully been able to call an API using python requests library. Need to make the same request in node.js. Saw various Q&As on SO and tried hard with the request library in node.js but ...

I have successfully been able to call an API using python requests library. Need to make the same request in node.js. Saw various Q&As on SO and tried hard with the request library in node.js but ...

  1. send post request javascript
  2. send post request python
  3. send post request curl
  4. send post request from chrome
  5. send post request online
  6. send post request java
  7. send post request postman
  8. send post request c#
  9. send post request powershell
  10. send post request php
  11. send post request from command line
  12. send post request golang
  13. send post request react
  14. send post request js
  15. send post request from terminal
  16. send post request html
  17. send post request in url
  18. send post request node
  19. send post request with parameters
  20. send post request to localhost

I have a scenario where I need to find and replace a number in a large string using javascript. Let's say I have the number 2 and I want to replace it with 3 - it sounds pretty straight forward until ...

I have a scenario where I need to find and replace a number in a large string using javascript. Let's say I have the number 2 and I want to replace it with 3 - it sounds pretty straight forward until ...

  1. regex exact match python
  2. regex exact match string
  3. regex exact match c#
  4. regex exact match javascript
  5. regex exact match java
  6. regex exact match r
  7. regex exact match url
  8. regex exact match powershell
  9. regex exact match substring
  10. regex exact match whole string
  11. regex exact match case insensitive
  12. regex exact match multiple words
  13. regex exact match mongodb
  14. regex exact match one of two strings

I am attempting to set up two analytics trackers in my Angular App. One of my requirements is to set up a tracker for every user that logs in to the app that forwards page tracking and event data to a ...

I am attempting to set up two analytics trackers in my Angular App. One of my requirements is to set up a tracker for every user that logs in to the app that forwards page tracking and event data to a ...

  1. angularjs google analytics event tracking
  2. angularjs google analytics
  3. angularjs google analytics example
  4. angularjs google analytics service
  5. angularjs single page google analytics
  6. angularjs directive for google analytics
  7. google analytics angularjs ui-router
  8. google analytics angularjs typescript
  9. google analytics angularjs controller