if/then statement in text box Adobe Acrobat X Pro

Using Adobe Acrobat X Pro: (I don't have any JavaScript experience)

I created a text box that calculates a #. I need one beside it with words based on the # in previous box. example:if number is 2.5 - 3.49 then "Meets Expectations" shows in the new box. There are 5 possible ranges and labels. (the others are: if <1.49 then "Unacceptable", if 1.5-2.49 "Needs Improvement", if 3.5-4.49 "Exceeds Expectations", and if>4.5 "Outstanding"

Is this possible, and if so, is anyone willing to tell me exactly how to do it?


Tina Engelmeyer


3 Answers

Voted Best Answer

Let's assume you have two fields - one contains the result of your calculation (let's call this Rating) and the second one contains the textual representation of that rating (called e.g. RatingText). Go into the properties of your RatingText field and bring up the Calculation tab, then select to create a custom calculation script and use the following script:

var n = this.getField("Rating").value;

if (n < 1.50) {
    event.value = "Unacceptable";
}
else if (n >= 1.50 && n < 2.5) {
    event.value = "Needs Improvement";
}
else if (n >= 2.5 && n < 3.5) {
    event.value = "Meets Expectations";
}
else if (n >= 3.5 && n < 4.5) {
    event.value = "Exceeds Expectations";
}
else if (n >= 4.5) {
    event.value = "Outstanding";
}

You will notice, that I am not using the 1.49, 2.49, 3.49 and 4.49 values - I am testing to see if the value is smaller than e.g. 1.5. That also covers 1.499 and 1.4999 and so on. Anything that is below 1.5 will be treated as Unacceptable. Once the average hits 1.5, we will treat it as the next category up.

Karl Heinz Kremer
PDF Acrobatics Without a Net
PDF Software Development, Training and More...
http://www.khkonsulting.com


By Karl Heinz Kremer   

Supposing the first text field is called "Text1" and the second "Text2" (you can change these names for the real ones later), you can place a script like this as a Custom Calculate Script in Text2 field:

var v1 = this.getField("Text1").value;

if (v1 <= 1.49) {
    event.value = "Unacceptable";
}
else if (v1 >= 1.5 && v1 <= 2.49) {
    event.value = "Needs Improvement";
}
else if (v1 >= 2.5 && v1 <= 3.49) {
    event.value = "Meets Expectations";
}
else if (v1 >= 3.5 && v1 <= 4.49) {
    event.value = "Exceeds Expectations";
}
else if (v1 >= 4.5) {
    event.value = "Outstanding";
}
if (isNaN(v1) || v1 === "") {
    event.value = "";
}

enter image description here

You can set Text2 field as Read Only:

enter image description here

And you can specify Text1 field format as number in Format tab and that the field value is in a range in Validate tab:

enter image description here

enter image description here


Almir R V Santos   

The "equal to" comparison operator is == so the last part of your code should be changed to:

else if (n == 0) {
    event.value = "Not Rated";
}


Almir R V Santos   


Please specify a reason: