Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript [SOLVED]Adding two items not working

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #30493
    nutt318
    Member

    This is code from the editable invoice (https://css-tricks.com/html-invoice/) and instead of an Invoice I was trying to make a Quote form.

    So where it says “Amount Paid” and have “Total Labor” and I see in the code its subtracting ‘Amount Paid’ from the total, but when I remove the ‘-‘ sign and add the ‘+’ sign it just adds both togeather like words for example’ $875.00100.00,

    Current code that I think is doing the math, but I just want to add them.

    function update_balance() {
    var due = $("#total").html().replace("$","") - $("#paid").val().replace("$","");
    due = roundNumber(due,2);

    $('.due').html("$"+due);
    }

    Thanks for the help.
    Jake

    #78426
    Chris Coyier
    Keymaster

    I think parseFloat() is what you’ll need there.

    var due = parseFloat($(“#total”).html().replace(“$”,””)) – parseFloat($(“#paid”).val().replace(“$”,””));

    And in fact, you probably don’t need the replace functions at all, parseFloat will ignore those.

    #78229
    nutt318
    Member

    That worked great!

    Thanks Chris.

    Can marked as solved.

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.