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
https://forums.phpfreaks.com/topic/116936-adding-number/
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
https://forums.phpfreaks.com/topic/116936-adding-number/#findComment-601805
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.