2 Replies Latest reply on Jan 19, 2010 10:26 AM by gkaiseril

# Using an option box with a calculation

Hi,

I have a calculation question for the group.  I am trying to calculate creatinine clearance.  Seems easy, but im getting stuck at the end.

creatinine clearance is : ((140-age)*weight (kg))  / (72*Scr)

Women are multiplied by 0.85 to get the final creatinine clearance result

I have a box for age, weight, and scr and the user enters the number.

Where I am getting stuck at is the end...I have an option checkbox for women so that the result is multiplied by 0.85.  I thought something like this might work...but to no avail.

var crcl2
crcl2 = (140 - this.getField('age').value) * (this.getField('weight').value) / (72 * this.getField('cr').value);

var crcl3
function validate(carbbox)
{
if (carbbox.checked == 1)
crcl3 == crcl2 * 0.85;
else
crcl3 == crcl2;
}

Im kinda new at this obviously....any help would be really appreciated.

thanks, chris

• ###### 1. Re: Using an option box with a calculation

Problem 1: You're not calling the function anywhere in this code, just

defining it.

Either drop the function definition, or call it from somewhere.

Problem 2: You're using the comparator (==) instead of the value assign (=)

operator in two places.

Problem 3: You're using "else" without placing the code before it in a block

(by placing curly brackets around it).

There are probably more, but that's the ones I see now...

• ###### 2. Re: Using an option box with a calculation

Unless you are repeating the calculation in the function at multiple places with different values or want a library type funciton that could be adeed to other forms, use of the function may not be needed.

event.value = ''; // assume calculation not performed
// perform calculation if divisor is not zero
if (this.getField('cr').value != 0) {