?
Solved

JavaScript in Adobe Acrobat

Posted on 2012-03-13
7
Medium Priority
?
443 Views
Last Modified: 2012-06-22
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 ...?
0
Comment
Question by:lsctech
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 37719678
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;
0
 

Author Comment

by:lsctech
ID: 37725674
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
0
 
LVL 44

Accepted Solution

by:
Karl Heinz Kremer earned 2000 total points
ID: 37725815
There are a couple of things that are not correct with your code:

1. Your fields are named yn_1..yn_10, but your loop goes over the fields yn_0..yn_9
2. You must have changed the export value for the checkboxes - the default is "Yes", but you are using "On". You need to change the script to reflect that as well.
3. I would initialize the variable extra_fee to 0 (and the line needs a ";" at the end).

Try this:

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

// get the fee
var fee = this.getField("Naturalist_Membership").value;
var extra_fee = 0;
if (this.getField("yn_extended").value == "On")
  extra_fee = 25;
 
// store the result in this text box
event.value = (CB_Count * 50) + fee + extra_fee;
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:lsctech
ID: 37726072
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
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 37726528
Ah... I see the same behavior here. Something must have happened when I copied/pasted the code. I am looking into it.
0
 
LVL 44

Assisted Solution

by:Karl Heinz Kremer
Karl Heinz Kremer earned 2000 total points
ID: 37726564
Found it...

You do not have a default state for the radio button. I assume it's wrong to not have anything selected for the membership level, so I would just define a default state (e.g. non-member) and that will take care of this problem. What you are seeing is that in the case of no selected option, the control returns "Off" instead of a value. If you do want the current behavior, just add the following like after you determine the fee:

if (fee == "Off")
    fee = 0;

This will force fee to a zero, and the total will be correct.

As I said, I would change the behavior of the radio button. If you still want "0" to be displayed when nothing is selected, just make a final check after you calculate the total:

var total =  (CB_Count * 50) + fee + extra_fee;
if (CB_Count == 0)
    total = 0;
event.value = total;
0
 

Author Closing Comment

by:lsctech
ID: 37726578
Thank you for your help!! that did it.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

*Adobe Acrobat 9 was used for this article.  Particular steps may vary depending on software versions. Adobe Acrobat has many, many variables that my be utilized to customize your forms for clarity and ease of use. The Form Editing Tool will be y…
The Adobe PDF proprietary file format is recognized as secure and formulated. But these PDF files are also prone to corruption and any external threat like virus attacks, improper storage can hit PDF file integrity.This type of damages can make cruc…
In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question