mhodgson

05-02-2007, 11:51 AM

Have a problem, hope someone can help,

If have worked on a script, where scoredage is a number like 8.5 (meaning years.months) and ageInMonths2 is a number like 60

<script type="text/javascript">

/** Function to calculate Scored Age variances**/

function variance(scoredage, ageInMonths2){

var yearfield = scoredage.split(".")[0]

var monthfield = scoredage.split(".")[1]

var yearfield = yearfield*12

var scoredmonths = parseInt(monthfield) + parseInt(yearfield)

var variance = scoredmonths - ageInMonths2

document.write(variance)

}

</script>

Seems to work fine as long as the final output 'variance' is positive. If the value ends up negative 'e.g. -21 or 0 then all I get displayed is NaN.

Can't figure out why?

The output is displayed in a repeat region of a php page and I found I had to put var on all the lines to get something to display on each row.

If have worked on a script, where scoredage is a number like 8.5 (meaning years.months) and ageInMonths2 is a number like 60

<script type="text/javascript">

/** Function to calculate Scored Age variances**/

function variance(scoredage, ageInMonths2){

var yearfield = scoredage.split(".")[0]

var monthfield = scoredage.split(".")[1]

var yearfield = yearfield*12

var scoredmonths = parseInt(monthfield) + parseInt(yearfield)

var variance = scoredmonths - ageInMonths2

document.write(variance)

}

</script>

Seems to work fine as long as the final output 'variance' is positive. If the value ends up negative 'e.g. -21 or 0 then all I get displayed is NaN.

Can't figure out why?

The output is displayed in a repeat region of a php page and I found I had to put var on all the lines to get something to display on each row.