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

JavaScript form field calculations

dlettow
Registered: Jan 24 2008
Posts: 20
Answered

I can't find a straight answer to this simple Acrobat JavaScript question through standard search (you try Googling "and"!), so I'm coming to the forum for help:

If I need two things to be true in an IF statement, what's the proper way in Acrobat JavaScript to form the .and.?

For example, here's the statement:
If Field_4E=100 .and. Field_4F<45, Field_4G="O"

Here's what I've tried in JavaScript based on what I've found online, but it doesn't seem to work:
var o4E = this.getField("4E");
var o4F = this.getField("4F");
var o4G = this.getField("4G");

if (o4E.value = 100 & o4F.value < 45) {
o4G.value = "O";
}

Any help would be greatly appreciated!

Donna

My Product Information:
Acrobat Pro 8.1.2, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Try:

// Get first two field values,
// and convert to numbers using + operator
var o4E = +getField("4E").value;
var o4F = +getField("4F").value;

// Get field object
var o4G = getField("4G");

if (o4E == 100 && o4F < 45) {
o4G.value = "O";
}


Where exactly do you want to place this code? Also, you should probably have an "else" clause in there to set the value of the "04G" field to something if those conditions are not met:

if (o4E == 100 && o4F < 45) {
o4G.value = "O";
} else {
o4G.value = "Something else";
}


George
dlettow
Registered: Jan 24 2008
Posts: 20
D'oh -- it's "&&" not "&"!Now it's working. Thank you so much!

Donna
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
And the test for equality is "==" not "=".

George
MACORP
Registered: Aug 12 2008
Posts: 1
Badly in need of some quick help. I have designed a form using adobe acrobat only. Not Adobe Designer. I need to have the form fields i created formatted so the entries are displayed as caps only. Is there a java script entry that can be entered in the form's text field properties, in the "Custom Form Script" section? I am new to java script. If so, would it reference each field's field name?
Bill at MACORP
Dimitri
Expert
Registered: Nov 1 2005
Posts: 1389
Hi MACORP,

You really should start a new thread for a new topic rather than hijacking someone elses' topic.

Here is an article at JavaScript Corner that discusses field formatting including an example file you can download with code for substituting text entered to uppercase. Look at the properties for that field the script is located under the format tab.

http://www.acrobatusers.com/tech_corners/javascript_corner/tips/2006/formatting_text_fields/

Hope this helps,

Dimitri
WindJack Solutions
www.pdfscripting.com
www.windjack.com
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
It is best to start a new thread for a new topic so all the responses apply to the original post.

Once can create a custom calculation script to convert the field's entry value to upper case, but this code will run every time any field is changed and in a large form this will be significant. The preferred method would be to create a custom keystroke, force to upper case as each key is pressed, or a custom format, force the field to upper case only upon commitment of the field. And whether you use the custom calculation, keystroke, or format you will need to write code for almost every field.

For the custom calculation script:

event.value = event.value.toUpperCase();

You really should review the eSeminars on demand on the AUC home page, the JavaScript How To's and get a copy of the Acrobat JavaScript API.

George Kaiser