Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

show and hide fields based on another field value equal to or greater than

New Here ,
Jan 23, 2017 Jan 23, 2017

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!

TOPICS
Acrobat SDK and JavaScript , Windows
5.7K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 24, 2017 Jan 24, 2017

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...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 24, 2017 Jan 24, 2017

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 24, 2017 Jan 24, 2017

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 24, 2017 Jan 24, 2017

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. .

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 24, 2017 Jan 24, 2017

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>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 24, 2017 Jan 24, 2017

Hmm theres a bunch of errors, let me check it out.    

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 27, 2023 Oct 27, 2023

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;


}

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 27, 2023 Oct 27, 2023

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?

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 27, 2023 Oct 27, 2023

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 27, 2023 Oct 27, 2023

Yes, as long as it's easy to find your code.

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 27, 2023 Oct 27, 2023
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 27, 2023 Oct 27, 2023

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 27, 2023 Oct 27, 2023

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

 

 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 27, 2023 Oct 27, 2023

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 27, 2023 Oct 27, 2023

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.

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 30, 2023 Oct 30, 2023

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.

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 30, 2023 Oct 30, 2023

Post the updated form and we'll take a look. I'm sure it's something simple. 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 30, 2023 Oct 30, 2023
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 30, 2023 Oct 30, 2023

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;
}

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 30, 2023 Oct 30, 2023

OMG you are a savior. Thank you so much! It's all sorted out. Can't thank you enough. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 30, 2023 Oct 30, 2023

Marking my post as the "correct answer" would be nice 🙂

Cheers,

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 31, 2023 Oct 31, 2023
LATEST

I did intend to do that but don't have the option. Only have upvote.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines