
1. Re: need help changing excel formula to javascript for medication order form
try67 Jul 21, 2016 1:50 PM (in response to neophyte1978)1 person found this helpfulAll of the methods you need to use are described here:
General tutorial about calculations in Acrobat: https://acrobatusers.com/tutorials/howtodonotsosimpleformcalculations

2. Re: need help changing excel formula to javascript for medication order form
Karl Heinz Kremer Jul 21, 2016 1:54 PM (in response to neophyte1978)1 person found this helpfulThe problem with translating such an Excel formula is that the round function is different in JavaScript. I would solve the problem like this (the following assumes that there are never any negative results):
var E6 = this.getField("Ht").value; var G6 = this.getField("Wt").value; var v = Math.pow(0.007184 * E6, 0.725) * Math.pow( G6, 0.425); if (v < 10.0) { // round to two decimal places event.value = Math.round(v * 100) / 100; } else if (v < 100.0) { // round to one decimal event.value = Math.round(v * 10) / 10; } else { // round to the nearest integer event.value = Math.round(v); }
You would use this as your custom calculation script in your result field.

3. Re: need help changing excel formula to javascript for medication order form
neophyte1978 Jul 22, 2016 6:49 PM (in response to try67)Very helpful indeed! Thank you!

4. Re: need help changing excel formula to javascript for medication order form
neophyte1978 Jul 22, 2016 6:51 PM (in response to Karl Heinz Kremer)Yes the rounding was where I had trouble. This worked perfectly! Thank you!

5. Re: need help changing excel formula to javascript for medication order form
neophyte1978 Sep 22, 2016 1:56 PM (in response to Karl Heinz Kremer)I'm trying to take this a step further. I have a field named Dose1 with the following code:
var v = this.getField("BSA");
event.value = Math.round(v.value * 125);
I then have a field named AdjDose1 that defaults to 100. I want to make it so that when any number below 100 is entered, it takes that percentage of the result of Dose1 and displays the new result in Dose1 field. For example:
Dose1 displays 250.
80 is entered into AdjDose1.
Dose1 now displays 200.
Is it possible to do this?
Thank you very much indeed in advance.

6. Re: need help changing excel formula to javascript for medication order form
George_Johnson Sep 22, 2016 7:04 PM (in response to neophyte1978)If this is for human medications, you really need do better. At minimum you need to validate the input values and the calculated results.

7. Re: need help changing excel formula to javascript for medication order form
neophyte1978 Sep 23, 2016 6:40 AM (in response to George_Johnson)Hi, yes I should clarify. I'm a pharmacist with 15 years of experience. I know I titled the thread Medication Order Form, however this form will be used as a tool to "doublecheck" separate, handwritten medication order forms. Nonetheless, the input values and custom calculations will be validated by two pharmacists other than myself.

8. Re: need help changing excel formula to javascript for medication order form
George_Johnson Sep 28, 2016 2:27 PM (in response to neophyte1978)1 person found this helpfulOK. You can change the calculation script to:
var v = this.getField("BSA");
var AdjDose1 = getField("AdjDose1").value;
if (AdjDose1 < 100) {
event.value = Math.round(125 * v.value * AdjDose1 / 100);
} else {
event.value = Math.round(125 * v.value);
}

9. Re: need help changing excel formula to javascript for medication order form
neophyte1978 Sep 28, 2016 1:48 PM (in response to George_Johnson)works perfectly. Thank You!!

10. Re: need help changing excel formula to javascript for medication order form
neophyte1978 Feb 9, 2017 3:05 PM (in response to George_Johnson)I have just ONE last calculation based on the above I'm hoping you could help with.
I need Dose1 to be result of 1.4 * BSA. If the result is >2, I need it to display 2. If less than 2, I need the result to be rounded to two decimal places but no hanging zeros (ex: 1.9 but not 1.90). Then as above, if any value less than 100 is entered into AdjDose1, that percentage of Dose1 is displayed in Dose1. For example:
when BSA = 1.35
Dose1 = 1.4 * 1.35
Dose1 = 1.89
AdjDose1 = 50
Dose1 now displays 0.95
when BSA = 1.7
Dose1 = 1.4 * 1.7
Dose1 = 2
AdjDose1 = 50
Dose1 now displays 1
Many thanks in advance!