Jump to content

Adding number


everisk

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.