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

Display Value in PDF Text Field On Condition

New Here ,
Feb 14, 2019 Feb 14, 2019

Copy link to clipboard

Copied

Hello,

I am trying to set up a form that will display the word "standard" in a field next to a paired checkbox if checked but otherwise keep the value of what the user types.

Right now, I have this in the custom calculation script for the text field called upper1:

var upper1= this.getField("upper1");

if (this.getField("Check1").value != "Off")

upper1.value = "Standard"

else

upper1.display = display.visible

Is there a different way that doesn't require overriding the value of upper1? I'd like to not overwrite the user-inputted value if possible and just have it selectively display the user value or not. User value could be blank if they don't want it.

Alternatively, I'd like to set it to display the export value of the checkbox when checked and the user-inputted value if unchecked.

TOPICS
Acrobat SDK and JavaScript

Views

397

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 , Feb 16, 2019 Feb 16, 2019

So lets be clear about what you are trying to do. On your form there is a text field next to a check box. User's can enter text into the text field.  If the check box is checked, then the word "Standard" is appended or prefixed onto to text the user entered?

The problem with this process. is that if the value of the field is modified you need to be able to parse the text field to remove the word standard. This is (slightly) problematic. It's much easier to have two fields as Bernd suggests. Or t

...

Votes

Translate

Translate
Community Expert ,
Feb 14, 2019 Feb 14, 2019

Copy link to clipboard

Copied

Use 2 fields. One with the value Standard. The other for the user input.

Votes

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 ,
Feb 16, 2019 Feb 16, 2019

Copy link to clipboard

Copied

I don't have the space for that.

Alternatively being able to clear out "standard" if unchecking but not over-riding any then user inputted value when I move to another line would be helpful.

Votes

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 ,
Feb 16, 2019 Feb 16, 2019

Copy link to clipboard

Copied

LATEST

So lets be clear about what you are trying to do. On your form there is a text field next to a check box. User's can enter text into the text field.  If the check box is checked, then the word "Standard" is appended or prefixed onto to text the user entered?

The problem with this process. is that if the value of the field is modified you need to be able to parse the text field to remove the word standard. This is (slightly) problematic. It's much easier to have two fields as Bernd suggests. Or to use the format event to add the appearance of the word "Standard', rather than changing the value of the text field.

To use the formatting solution, do this. Remove the calculation script.  Add this code to a custom format script for the text field.

if (this.getField("Check1").value != "Off")

    event.value = "Standard - " + event.value;

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

Votes

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