Avatar of lsctech
lsctech
 asked on

JavaScript in Adobe Acrobat

I have a series of check boxes, 5 of them to be specific.  I then have a radio button for member or non member and one more check box for additional service fee.  I then have a total text box.

What I would like to do is have the script calculate the total off of the radio button value they are set to 110 and 130.  then multiply the number of check boxes checked by 50$ and add the additional service fee to the total if checked.  I would like this amount to show up in the Total value text box.

I am not sure how to do the radio buttons. would I do 2 if statements? one for if(this.getField("Naturalist_Membership").value == "110" then ... and one for if (this.getField("Naturalist_Membership").value == "130" then ...?
JavaScriptAdobe Acrobat

Avatar of undefined
Last Comment
lsctech

8/22/2022 - Mon
Karl Heinz Kremer

I would use the following as the calculation script for the result text box:

// Count the checked check boxes
var CB_Count = 0;
var baseName = "CB.";
for (var i=0; i<5; i++)
{
    if (this.getField(baseName + i).value == "Yes")
        CB_Count++;
}

// get the fee
var fee = this.getField("Naturalist_Membership").value;

// store the result in this text box
event.value = (CB_Count * 50) + fee;
lsctech

ASKER
Here is my exact code. I will also attach my PDF version.  I can not get it to display any text in the textbox. Please help! Thanks.

// Count the checked check boxes
var CB_Count = 0;
var baseName = "yn_";
for (var i=0; i<9; i++)
{
    if (this.getField(baseName + i).value == "Yes")
        CB_Count++;
}

// get the fee
var fee = this.getField("Naturalist_Membership").value;
var extra_fee
if (this.getField("yn_extended").value == "Yes")
  extra_fee = 25;
 
// store the result in this text box
event.value = (CB_Count * 50) + fee + extra_fee;
BHNPsummer-camps-registration-20.pdf
ASKER CERTIFIED SOLUTION
Karl Heinz Kremer

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
lsctech

ASKER
Ok awesome that works! the only thing is how do I get it not to say 0Off0 in the total text box.  I would be ok with it just saying 0
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Karl Heinz Kremer

Ah... I see the same behavior here. Something must have happened when I copied/pasted the code. I am looking into it.
SOLUTION
Karl Heinz Kremer

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
lsctech

ASKER
Thank you for your help!! that did it.