View Full Version : addition not concatination!!

04-19-2005, 06: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.

<!-- 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 -->

Where is my fundamental mistake? Thanks.

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

example would be

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


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