...

View Full Version : Simple addition problems



jamie85
10-15-2005, 06:27 PM
This code should add the value from the xml element, and add it to distance.
However, instead of distance increasing in size, it returns the value...'05678', rather than 26.

What am i doing wrong??

Much appreciated.



function calc_distance()
{
var y = xmlDoc.getElementsByTagName('distance');
var distance = 0;

for ( a = 0; a < y.length; a++ )
{
distance += y[a].firstChild.nodeValue;

alert(distance);
}

}

gph
10-15-2005, 07:40 PM
alert(typeof distance)

parseFloat(y[a].firstChild.nodeValue)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum