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

Custom Calculation question

RudyPT
Registered: Oct 26 2009
Posts: 9
Answered

Hi - I am developing a PDF, and have been able to get by with "simplified field notations" performed for me up to this. Unfrotuantely, now I am stuck and I do not know where to turn for help. The Javscript world is forign to me. Thus, I apologize upfront for my ignorance.

This is what I am trying to accomplish. I wish to have field "Text34" equal a rank number 0, 1, 2, or 3 based upon the data (number) entered into field "Text15"

in other words, if "Text15" were greater than or equal to 3.75 then "Text34" would equal 3. Or, if "Text15" is less than or equal to 3.25 then "Text34" would equal 0.

I hope this makes sense? I would greatly appreciate any help anyone might be willing and able to offer.

Thanks, Rudy

My Product Information:
Acrobat Pro 7.0, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
There's nothing unusual about the calculation you want to do. It's called a "Conditional Calculation". There are some rules for writing calculation scripts. Take a look at these web pages:

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

http://www.pdfscripting.com/public/department45.cfm

For your script you'll need to use an "if" statement.

For example:

var val1 = this.getField("Text15").value
if(val1 >= 3.75)
event.value = 3;


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

RudyPT
Registered: Oct 26 2009
Posts: 9
Thomp - you are my hero. :)

Thanks for the help and referral. How do i denote a range, i.e. 3.50-3.74 = 2?

Do I add them within the same script line?

Thanks Again, Keith
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
For a range you'd use a compound "if" like this:

if( (val1 > 3.5) && (val1 <= 3.74) )
event.value = 2;

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

RudyPT
Registered: Oct 26 2009
Posts: 9
Dear Thom - thanks again. You ahve helped me more than I could imagine.

Sincerely, Keith