Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

JavaScript in Adobe Acrobat

Posted on 2012-03-13
7
Medium Priority
?
445 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
Industry Leaders: 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Have you ever come up with a need of emailing only few pages of PDF file to one of yourfriend or colleague, instead of whole Adobe file? If yes, then surely you have face problems in doing that! Read this section as I have suggested multiple solutio…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
In this second video of the Xpdf series, we discuss and demonstrate the PDFimages utility, which, in a single command, is able to extract all the images from a PDF file and save each one in a separate image file (PBM, PPM, or JPG). Download and inst…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …

610 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