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

Show/Hide field based on a choice from a dropdown field which contains a specific word

New Here ,
Jun 19, 2019 Jun 19, 2019

Copy link to clipboard

Copied

I have a dropdown field (Type_Study) with 10 options, 4 of which begin with the word "Sensitization."

I have 2 fields which only need to be visible if:

a) the choice from the dropdown includes "Sensitization" or "all", and

b) if a different dropdown (Storage1) is not equal to "Select Option"

I believe I would need to add a custom calculation script to the fields to be visible or hidden and I have the script to make the field visible based on b) but I do not know how to script a) and combine it with b).

So far, I have:

if (this.getField("Storage1").value != "Select Option") {    

event.target.display = display.visible;

} else {

event.target.display = display.hidden;

}

Any help would be appreciated.

Thanks,

Jane

TOPICS
Acrobat SDK and JavaScript , Windows

Views

411

Likes

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , Jun 21, 2019 Jun 21, 2019

No need, it's possible to check if one value contains another, it's just a bit trickier.

Try this code:

var v1 = this.getField("Type_Study").valueAsString;

var v2 = this.getField("Storage1").valueAsString;

if ((/All 3 Assays/.test(v1) || /DPRA/.test(v1) || /KeratinoSens/.test(v1)) && v2!="Select Option") {

    this.getField("Field1").display = display.visible;

    this.getField("Field2").display = display.visible;

} else {

    this.getField("Field1").display = display.hidden;

    this.getField("Fi

...

Likes

Translate

Translate
Community Expert ,
Jun 20, 2019 Jun 20, 2019

Copy link to clipboard

Copied

Because you want to do it based on the value of multiple fields, it's a bit more complicated.

You can use this code as the custom calculation script of a (hidden) text field to achieve it:

var v1 = this.getField("Sensitization").valueAsString;

var v2 = this.getField("Storage1").valueAsString;

if ((/Sensitization/.test(v1) || /all/.test(v1)) && v2!="Select Option") {

    this.getField("Field1").display = display.visible;

    this.getField("Field2").display = display.visible;

} else {

    this.getField("Field1").display = display.hidden;

    this.getField("Field2").display = display.hidden;

}

You'll need to enter the actual field names in lines 4, 5, 7 and 8, of course.

Edit: code fixed

Likes

Translate

Translate

Report

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 ,
Jun 20, 2019 Jun 20, 2019

Copy link to clipboard

Copied

There was a mistake in the code above. I fixed it now.

Likes

Translate

Translate

Report

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 ,
Jun 21, 2019 Jun 21, 2019

Copy link to clipboard

Copied

Thank you for this but I am still not able to make it work. I realize that I was not clear enough in the parameters and conditions, nor am I sure which field to attach the script to, so I would like to start over...

1) Would I build the custom calculation script in the field that is currently hidden but needs to be visible when the parameters/conditions are met?

and

2) Assuming 1 is correct, here are my parameters, which are identical for both of the fields:

  • 1st Dropdown field name is "Type_Study" and conditions to be met are EITHER that the selection from the dropdown contains "All 3 Assays", "DPRA" or "KeratinoSens".
  • 2nd Dropdown field name is "Storage1" and the selection should not be equal to "Select Option"
  • Both dropdown conditions need to be met for the field to be visible.

Thanks for your help try67!

Jane

Likes

Translate

Translate

Report

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 ,
Jun 21, 2019 Jun 21, 2019

Copy link to clipboard

Copied

1) You can put it under one of those fields, yes.

2) You keep writing "contains". Do you mean "equals"? The two require quite different approaches, and the latter is much simpler.

Likes

Translate

Translate

Report

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 ,
Jun 21, 2019 Jun 21, 2019

Copy link to clipboard

Copied

OK, thanks.

I was hoping not to have to spell out the full value... hence my use of contains but if equals is simpler, I can write the full text of the field. Let's do that and I will replace my text in " " with full text.

Many thanks.

Jane

Likes

Translate

Translate

Report

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 ,
Jun 21, 2019 Jun 21, 2019

Copy link to clipboard

Copied

No need, it's possible to check if one value contains another, it's just a bit trickier.

Try this code:

var v1 = this.getField("Type_Study").valueAsString;

var v2 = this.getField("Storage1").valueAsString;

if ((/All 3 Assays/.test(v1) || /DPRA/.test(v1) || /KeratinoSens/.test(v1)) && v2!="Select Option") {

    this.getField("Field1").display = display.visible;

    this.getField("Field2").display = display.visible;

} else {

    this.getField("Field1").display = display.hidden;

    this.getField("Field2").display = display.hidden;

}

(I'm still not sure what are the names of the fields you want to show/hide...)

Likes

Translate

Translate

Report

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 ,
Jun 24, 2019 Jun 24, 2019

Copy link to clipboard

Copied

LATEST

Great! Thank you.

Likes

Translate

Translate

Report

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