everisk Posted July 28, 2008 Share Posted July 28, 2008 Hi, I have a function where I'll add value of all array (named amnt) after a button is clicked. However, the function doesn't seem to loop correctly (it seems to be running forever) and didn't output the totalAmnt value in the last line. Below is my code. How do I fix this? Thanks. function calculateTotalAmnt() { var loopno = parseFloat(document.getElementById("serviceno").value); var totalAmnt = parseFloat(0); var i; for(i = 0; i<=loopno; i++) { var toget = "amnt["+i+"]"; totalAmnt = parrseFloat(totalAmnt) + parseFloat(document.getElementById(toget).value); } document.write("here"+totalAmnt); //this output doesn't show } Link to comment https://forums.phpfreaks.com/topic/116936-adding-number/ Share on other sites More sharing options...
lemmin Posted July 28, 2008 Share Posted July 28, 2008 There is a much easier way to do this, if you show your HTML I can give you an example. As for your javascript right now, you have: totalAmnt = parrseFloat(totalAmnt)... There are two 'r's in your parseFloat method, but I'm pretty sure it would work the same without that method there at all. Link to comment https://forums.phpfreaks.com/topic/116936-adding-number/#findComment-601805 Share on other sites More sharing options...
everisk Posted July 29, 2008 Author Share Posted July 29, 2008 Hi Lemmin, thank you noticing my mistake. Silly me. After i take out the extra 'r' it works. Thank you so much for your help. Link to comment https://forums.phpfreaks.com/topic/116936-adding-number/#findComment-602296 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.