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

It WORKS but am I going about this the right way?

RustyWood
Registered: Mar 16 2010
Posts: 83

Could someone tell me if this is the right way to go about this?

It all works OK, but I'm just not sure if this how it should be done?


These are calculations in a row for one participant. There are 28 participants in the column per sheet order form.

Hope that makes sense, probably not!!



*********************************************************************************

NAME IN TEXT BOX (text box for participants name)

TEXT BOX # OF CARDS IN THIS PACK (add the number of cards in a pack)

REGULAR PRICE PER PACK IN £ (text box @ 35p each)

simplified field notation

par_1_num_cards_in_pack * 0.35
CHECK BOX 1 PACK (value each = 1) 

MOUSE UP, RUN A JAVASCRIPT




var a = this.getField("par_1_pack_num_less_10_percent_quantity").value;
if(a >=2)
  event.value = this.getField("par_1_single_pack_reg_price").checkThisBox(0,false);

TEXT BOX PRICE PER PACK WITH 10% OFF IN £ ( 2 or more packs)

CUSTOM CALCULATION SCRIPT

var a = this.getField("par_1_num_reg_price_at_0.35").value;
event.value = a * 0.90;

TEXT BOX (add a value of 2 or more packs)

CUSTOM CALCULATION SCRIPT


var a = this.getField("par_1_pack_num_less_10_percent_quantity").value;
if(a <=1)
  event.value = 0;
if(a >=2)
  event.value = this.getField("par_1_single_pack_reg_price").checkThisBox(0,false);

TOTAL AMOUNT IN £ (amount for each participant)

CUSTOM CALCULATION SCRIPT

var a = this.getField("par_1_single_pack_reg_price").value;
var b = this.getField("par_1_num_reg_price_at_0.35").value;
var c = this.getField("par_1_price_less_10_percent").value;
var d = this.getField("par_1_pack_num_less_10_percent_quantity").value;
if(a == "Off")  
  event.value = 0 ;
else if(a == 1)  
  event.value = a * b;
if(d >= 2)  
  event.value = (c * d);

TOTAL PACK OF CARDS SOLD PER PARTICIPANT

CUSTOM CALCULATION SCRIPT

var a = this.getField("par_1_single_pack_reg_price").value; 
var b = this.getField("par_1_pack_num_less_10_percent_quantity").value;
  event.value = 0; 
if(a == 1)
  event.value = 1; 
else if(b >= 1)
  event.value = b;

ADMIN USE TOTAL SHEETS OF SRA3

CUSTOM CALCULATION SCRIPT

var a = this.getField("par_1_num_cards_in_pack").value; 
var b = this.getField("par_1_total_packs_cards").value;
event.value = a * b / 3;

With thanks

My Product Information:
Acrobat Standard 9.3.1, Macintosh
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
You have a couple of issues with this code, but nothing horribly fatal;)

First, the "checkThisBox()" function does not return a value, so it makes no senes to apply it to "event.value". In this line for example:

event.value = this.getField("par_1_single_pack_reg_price").checkThisBox(0,false);

The "event.value" property is not valid in the MouseUp Event, Makes no sense here.

And just in general, when a script is refering to the field that it is running in, always reference properties of that field through the event Object, "event.target"

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]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

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

RustyWood
Registered: Mar 16 2010
Posts: 83
Thank you very much Thomp.

This is the first form I have tackled, so your feedback is very much appreciated.

Would this be a better way to write it.

var a = this.getField("par_1_pack_num_less_10_percent_quantity").value;if(a >=2)event.target.checkThisBox(0,false);

I found if I don't add this to the check box then it can still be checked when the field
"par_1_pack_num_less_10_percent_quantity" has a value of more than 2.

With Thanks

Rusty