These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Caculation based on radio dial values

407chelsie
Registered: Dec 8 2008
Posts: 68

I have posted [url=http://idisk.mac.com:80//chelsie.hall/Public/App-RM-09117-2.pdf]the example here[/url].

I received help from gkaiseril on this topic but now the client has changed it again and despite my best efforts, I'm unable to get the code edited properly. The existing code is:

// total membership dues custom calculation
 
// Compute Total Membership Dues
// Get number of membership dues, as a number
var mem_dues = this.getField("Membership Classification").value;
// if not a number set to zero
if (isNaN(mem_dues) == true ) mem_dues = 0;
this.getField('Membership Dues').value = mem_dues;
// assume field is hidden, display if none zero
// get Membership dues object
var oMem_Dues = this.getField('Membership Dues');
oMem_Dues.display = display.hidden;
if (mem_dues > 0) 
oMem_Dues.display = display.visible
 
// compute specialty membership total 
// get field values
var ceesp = this.getField("Chief Audit Executive Services Program").value;
var fsag = this.getField("Financial Services Auditor Group").value;
var gag = this.getField("Gaming Audit Group").value;
var spec_sum = 0;
// set any non-numberic values to zero
if(isNaN(ceesp) == true) ceesp = 0;
if(isNaN(fsag) == true) fsag = 0;
if(isNaN(gag) == true) gag = 0;
// compute value
spec_mem = Number(ceesp) + fsag + gag;
this.getField('Specialty Membership Total').value = spec_mem
// assume field is hidden, display if none zero
// get Membership dues object
var oSpec_Mem = this.getField('Specialty Membership Total');
oSpec_Mem.display = display.hidden;
if (spec_mem > 0) 
oSpec_Mem.display = display.visible
 
// compute total dues
event.value = mem_dues + spec_mem;
// assume field is hidden, display if none zero
this.getField(event.target.name).display = display.hidden;
if (event.value > 0) 
this.getField(event.target.name).display = display.visible

I need to change this so that the "Application Fee" changes dependent on the "Membership Classification" selected. It needs to be $25 if the first radio button is selected and $0 if another button is selected AND hidden if no selection has been made.

PLEASE HELP. I'm in WAY over my head!

My Product Information:
Acrobat Pro 8.1.2, Macintosh
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
You seem to be doing a lot in a single calculation. Since you have a 'Membership Dues' field, why not put the for the dues calculation there, including the hide/show for the field. This will clean up the code quit a bit.

Then all this calculation needs to do is acquire that value.

You also don't need this code, it's redundant.

this.getField(event.target.name).display

instead, use this:

event.target.display

Now, the way the Membership dues calculation is setup, you don't need to do anything to the code to change the value of the membership due. All you have to do is change the export value of the Radio Buttons.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

407chelsie
Registered: Dec 8 2008
Posts: 68
The membership dues value is separate from the application fee. These radio buttons somehow have to hold two values, the dues and the fee associated with that selection. Thanks for your ongoing help.
407chelsie
Registered: Dec 8 2008
Posts: 68
I fear I wasn't clear before.
NEW WAY TO POSE THE QUESTION:

How can I get two values associated with each radio button. The example is:
(A) Standard Membership - $145 [i](Application Fee $25)[/i]
(B) Education Membership - $75 [i](Application Fee $0)[/i]
(C) Student Membership - $35 [i](Application Fee $0)[/i]
(D) Government Membership - $75 [i](Application Fee $0)[/i]
Application Fee _____
Membership Dues _____
Total _____

This is the last hurdle in this project and I'll be done. Any help would be greatly appreciated.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
The easy way is to put both values in the export for the radio button as a single string.

For example: "145:25"

Then when the code gets the value from check box, just split it and assign the values to the different fields. Here's an article on handing strings in just this way:

http://www.acrobatusers.com/tutorials/2006/string_splitting

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

407chelsie
Registered: Dec 8 2008
Posts: 68
I'm excited because I know that your recommendation is the solution to my problem, but I am having difficulty executing it.

I have put the two values in each radio button like your example "145:25" and have placed the following script for the calculation of the Application Fee:
var mem_class = this.getField("Membership Classification").value;// split Membership Classification value to get the App Feevar app_fee = mem_class.split(":");

I'm obviously missing the part that says to get the number following the ":" and place it in this field. What exactly should this calculation script look like? I'm so confused. I've read the tutorial 3 times, but since this is my first JavaScripting project, it blows right over my head.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
You're doing great so far. The values are now members of an array. So you could assign them to 0ther fields like this.

this.getField("memDues").value = app_fee[0];
this.getField("appFee").value = app_fee[1];

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

407chelsie
Registered: Dec 8 2008
Posts: 68
Oh Goodness. I think I'm making a big mess. I applied the code you suggested, but now I'm getting an error that says, "The value entered does not match the format of the field [ Membership Dues ]" and "The value entered does not match the format of the field [ Application Fee ]".

My right brain was lucky to get the first ten applications finished. This one might just keep me from scripting ever again. [b]Pretty Please,[/b] if you have a moment to look at [url=http://idisk.mac.com:80//chelsie.hall/Public/App-RM-09117-2.pdf]the PDF[/url] and tell me what I need to change, I'll be out of this forum's hair for a while. Thank you so much.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
I'm sorry, I usually only do analysis on PDFs for customers (it takes time, you know). However, the error you're getting is a completly different thing from the script that's setting the field values. For now, remove the formatting from the fields so you can check the results of the calculation. When your scripts are correct, then you can re-apply the field formatting.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

407chelsie
Registered: Dec 8 2008
Posts: 68
I have removed the formatting which revealed a lot. I now have the App Fee working (it is grabbing the second value of the radio button) but I can't duplicate my success in the Mem Dues. The value seems to be there, but not visible. The total is including the Mem Dues value, so why is it not showing?
407chelsie
Registered: Dec 8 2008
Posts: 68
Oops, forgot the link. My latest [url=http://idisk.mac.com:80//chelsie.hall/Public/App-RM-09117-3.pdf]PDF is here[/url].

And, I totally understand the need to charge for our expertise (especially in this economy). But, since this is a non-profit client, I appreciate any free guidance you are willing to share.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Ok, now you need to do some debug with the Console Window. Here's an article that will get you going.

http://www.acrobatusers.com/tutorials/2006/javascript_console

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script