show and hide fields based on another field value equal to or greater than
Copy link to clipboard
Copied
Good evening,
I want to show and hide a field based on another field's numerical value being equal to or greater than. The scenario is, if one field name "text1" (which has a calculation formula of its own) is equal to or greater than 50k, I want the form to show 7 other fields. If its less than 50k then I want those fields to be hidden. Therefore, those fields should be always hidden unless the value goes 50k+ in "text1". I have been looking around for a while been the syntax I keep getting doesnt seem quite right.
Thanks in advance!
Copy link to clipboard
Copied
At the end of your calculation script for "text1" add this code:
if (event.value>=50000) {
this.getField("field1").display = display.visible;
this.getField("field2").display = display.visible; // etc.
} else {
this.getField("field1").display = display.hidden;
this.getField("field2").display = display.hidden; // etc.
}
Edit: Added the "equals to" operator...
Copy link to clipboard
Copied
Thanks for this!
I inputed your code after the calculation code and doesnt seem to work correctly. When I place a value that is above 50000 it doesnt hide the field. This is how I have it:
var total = this.getField("Fee rate").value * this.getField("Quantity").value + this.getField("Cap for related expenses ie cost of meals travel other incidentals etc").value;
this.getField("Total SOW value").value = total;
if (event.value>=50000) {
this.getField("Text2").display = display.visible;
} else {
this.getField("Text2").display = display.hidden;
}
Thanks in advance.
Copy link to clipboard
Copied
You said in your original message that you wanted to show the fields if the value is >50K... If you actually want to hide them then replace "display.visible" with "display.hidden", and vice versa.
Copy link to clipboard
Copied
So i first tried it with your code to one field and it didnt work. The field remains hidden if the value is 50k or higher.
Then I tried to keep the fields visible and use a large field to cover all the rest and hide it when it reaches 50k or higher. .
Copy link to clipboard
Copied
My code should work. Check the JS-Console (Ctrl+J) for any error messages...
On Tue, Jan 24, 2017 at 4:22 PM, stevenc65695984 <forums_noreply@adobe.com>
Copy link to clipboard
Copied
Hmm theres a bunch of errors, let me check it out.
Copy link to clipboard
Copied
I used this and it works; however, when I tested as a person filling out my form and revised the amounts in the fields, the change did not get picked up to re-hide the field.
event.value=((this.getField("Text3").value));
if (event.value>0) {
this.getField("check5").display = display.visible;
} else {
this.getField("check5").display = display.hidden;
}
Copy link to clipboard
Copied
The script looks like it could have a couple of issues.
Where is this script used. What field name and which event?
Also, what PDF viewer did you use to test filling the form?
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
I created a document level javascript string. I'm sorry but I'm not very expeirenced and am not sure what you mean by what field name and which event. I am using Adobe Acrobat Pro, which is also what I used to test. Can I share a link to my form?
Copy link to clipboard
Copied
Yes, as long as it's easy to find your code.
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Copy link to clipboard
Copied
I have 2 checkboxes that are hidden and are supposed to appear at the same time the yellow ! warnings appear. Sometimes they do, sometimes they don't, then if the amounts are changed, they don't show/hide as they should based upon the changes.
Copy link to clipboard
Copied
So, all of the document level scripts are non-functional. Document scripts are executed when the PDF is opened, so event.value has no meaning. Delete all of them.
Add the code for showing and hiding the checkboxes into the existing calculation scripts for Text3 and Text4
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
I have other script in there already, for both. I'm wondering if I'm not doing it correctly since I have multiple things going on in that field, because I tried a couple different things and the checkboxes are still not working properly.
Copy link to clipboard
Copied
It works just fine putting the hide/show checkbox code in the calculation. Maybe what you are seeing is the square graphic behind the checkbox when its not visible. Get rid of it if you don't want to see a thing that looks like it might be a checkbox.
But the document scripts are completely and totally worthless. Delete them all.
Under what exact conditions do you want the checkboxes to hide/show. Be specific.
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
I appreciate your help with this. My knowledge is basic and based on what I can find online and sometimes it's hard to find someone who had the exact same scenario to use as a reference.
I deleted the document scripts Friday before I posted my last message and moved to the Text3 and Text4 calculation scripts and they are not working. The warning tringles appear when the Actual cost per-person has exceeded the per-person max; and when the Actual tip/gratuity has exceeded the Tip/gratuity max. What I want to happen is this: Check5 and Check6 checkboxes should not show by default. When the per-person max has been exceeded (and the warning triangle is showing), the check5 checkbox should show. When tip/grauity max has been exceeded (and the warning triangle is showing), check6 checkbox should show.
Copy link to clipboard
Copied
Post the updated form and we'll take a look. I'm sure it's something simple.
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Ok, so lets take a look at the code:
event.value=((this.getField("Actual cost perpersonRow1").value))-((this.getField("Perperson maxRow1").value));
if (event.value>0) {
this.getField("warning ppm").display = display.hidden;
} else {
this.getField("warning ppm").display = display.visible;
}
event.value=((this.getField("Text3").value));
if (event.value>0) {
this.getField("check5").display = display.visible;
} else {
this.getField("check5").display = display.hidden;
}
This is a calculation script for the "Text3" field. The first line performs the calculation and sets the field value in "event.value".
This is exactly how PDF form calculations are supposed to work.
Then next set of lines use this newly calculated value to set the visibility of the field blocking he warning triangle.
This code is also perfect. Done just the way it's supposted to be.
But the last bit of code is incorrect. The actual value of the "Text3" field has yet to change. This calculation script is setting the proposed value. There are still other field events that have to be run before the value is committed.
It is improper to ever try to acquire the value of a field directly in it's own calculation script. All field access is done through the event object. It is especially problematic to reset "event.value", since it's already been set.
Besides, this code is completly unnecessary. You already have the value, and an "if" block that uses it.
Here's the corrected code.
event.value=((this.getField("Actual cost perpersonRow1").value))-((this.getField("Perperson maxRow1").value));
if (event.value>0) {
this.getField("warning ppm").display = display.hidden;
this.getField("check5").display = display.visible;
} else {
this.getField("warning ppm").display = display.visible;
this.getField("check5").display = display.hidden;
}
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
OMG you are a savior. Thank you so much! It's all sorted out. Can't thank you enough.
Copy link to clipboard
Copied
Marking my post as the "correct answer" would be nice 🙂
Cheers,
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
I did intend to do that but don't have the option. Only have upvote.

