Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript in Adobe Acrobat 7.0 Pro

Status
Not open for further replies.

napatamm

Programmer
Oct 5, 2008
44
US
I'm working on a form that needs calculations. For example, I have to take three text fields, multiply them by 1.73 and divide that result by 1000. I'm not sure how to write a custom calculation script for this. Help?

I tried to take it one day at a time, but a whole bunch of them attacked me at once!
 
what have you done so far? Can we see at least your form and any attempts you've made?

This forum isn't to get others to write code for you, rather it's to get help with code you've written/attempted.

--------
GOOGLE is a great resource to find answers to questions like "how do i..."

If you don't know exaclty what you want to do or what to search on, try Google Suggest: --------
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javasc
 
I actually am quite unsure of where to start with the code in Adobe. I'm used to writing code in an HTML document. Here's what I have written and it really doesn't like it. Do I need to declare a function or write an entire script rather than writing just a statement?

In text field 4.8 I need to multiply the fields Text4.3, Text4.7, Text4.10, and the number 1.73 then divide the product by 1000.

Code: document.write("Text4.3"*"Text4.7"*"Text4.10"*1.73/1000);

I did not get a syntax error message with this, but it's not working. The only Javascript I've ever worked with in Adobe Acrobat is a submit button to send a PDF form through email.

Thanks for any advice on what I'm doing wrong...

I tried to take it one day at a time, but a whole bunch of them attacked me at once!
 
sorry, writing js within adobe products is not my thing either - I could have helped if it was regular HTML/JS (but they you probably wouldn't of need the help)

Good luck

--------
GOOGLE is a great resource to find answers to questions like "how do i..."

If you don't know exaclty what you want to do or what to search on, try Google Suggest: --------
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javasc
 
Now I haven't had much experience with Adobe JS either, but something like this should get you on the right track at the very least:

Code:
var f = this.getField("nameoffieldone");
var g = this.getField("nameoffieldtwo");
var h = this.getField("nameoffieldthree");


f.value = (f.value * 1.73) / 1000;
g.value = (g.value * 1.73) / 1000;
h.value = (h.value * 1.73) / 1000;




----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Here's what I've got so far:

var f=this.getField("Text4.3");
var g=this.getField("Text4.7");
var h=this.getField("Text4.10");
var r=(f.value*g.value*h.value);
var s=(r.value*1.73);
var t=(s.value/1000);

Calculate.value=t.value

But now I get the following message in the debugger:

ReferenceError: Calculate is not defined
8:AcroForm:Text4.8:Calculate

So I'm thinking that I need to define a function just like when I'm coding for HTML?

I tried to take it one day at a time, but a whole bunch of them attacked me at once!
 
Dan's right.

What is Calculate? How do we know it has a 'value' property?




----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
See? This is where I'm completely ignorant. I just finished a Javascript class for HTML, but Adobe has to go and reformat the whole dang thing and confuse the newbie.

I know how to create form fields in Acrobat, but trying to figure out how functions work is a bear. Should I try writing a regular function to calculate the whole thing and deliver the value to the form field just like I would with an HTML page?

I tried to take it one day at a time, but a whole bunch of them attacked me at once!
 
Should I try writing a regular function to calculate the whole thing and deliver the value to the form field just like I would with an HTML page?

Surely it would have been quicker to try it for yourself than ask the question and wait overnight for an answer?

So, give it a try. The worst that can happen is that it doesn't work. I doubt you'll be in any danger of reformatting your HDD, etc, with a bit of JS.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top