PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Mon Sep 23, 2019 3:20 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Thu Dec 17, 2015 9:25 am 
Offline
Forum Newbie

Joined: Sun Nov 22, 2015 10:19 am
Posts: 4
Syntax: [ Download ] [ Hide ]
        newArray = [];
        function AddAnotherExpense(detail, amount){    
                var newArray2 = { "detail" : detail, "amount" : amount };
                newArray.push(newArray2);
                //console.log(newArray);
        };

        total = 0;
        $("input[name=addAnotherExpense]").on("click", function(e){
                e.preventDefault();
                var expenseDetail = $("input[name=expenseDetail]").val();
                var expenseAmount = parseFloat($("input[name=expenseAmount]").val());
                AddAnotherExpense(expenseDetail, expenseAmount);
               
                for(i=0; i<newArray.length;i++)
                {      
                        amount = parseFloat(newArray[i].amount);
                        total = parseFloat(total) + amount;
                        console.log("total in for loop = " + total);
                }
                $("#totalExpensesParagraph").append(total);
        });


Hi guys please view the above jquery code, I am converting the input into a float using parseFloat in 3 different places but upon logging the output to the console I am still getting the error "total in for loop = NaN". I just want the totals in the object added and not be a string concatenation.


Top
 Profile  
 
PostPosted: Thu Dec 17, 2015 10:55 am 
Offline
Forum Newbie

Joined: Sun Nov 22, 2015 10:19 am
Posts: 4
ok guys what I did was put the parsefloat on the actual amount input element and that solved the NaN problem, but my calculations are still off somehow, any ideas?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group