...

View Full Version : addition not concatination!!



pdug175
04-19-2005, 05:50 PM
I've never used JS before, after reading around here and searching on google I came up with a script that takes the value of a radio button and adds it to the value of the next radio button.

All my code seems logical except instead of adding the two numbers together the code is concatenating the two.



<script>
<!-- Begin
var understands, coverage, detail, logical;
var average;
function getRadios(what){


j=what.understands.length; //alert(j)
for (i=0; i<j; i++)
{
if(what.understands[i].checked) var average = what.understands[i].value
}

for (i=0; i<j; i++)
{
if(what.coverage[i].checked) var average = average + what.coverage[i].value
}

what.grade.value = (average)
}
// End -->
</script>




Where is my fundamental mistake? Thanks.

A1ien51
04-19-2005, 05:57 PM
you need to use parseInt or parseFloat

example would be

intVar = parseFloat(document.formName.elementName.value) + parseFloat("123");

Eric

pdug175
04-19-2005, 06:46 PM
painless, thank you :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum