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 } Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.