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

if then

New Here ,
Aug 22, 2022 Aug 22, 2022

Copy link to clipboard

Copied

Hi,

 

I have two questions;

 

1. How to make if another cell filled with text then another cell is equal to 1.

2. How to make if another cell not blank then another cell is equal to not blank + 1. 

 

Thank you

TOPICS
PDF forms

Views

277

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 ,
Aug 22, 2022 Aug 22, 2022

Copy link to clipboard

Copied

Let's say you have fields "Text1" and "Text2".

1, You want to make "Text2" value 1 if "Text1" is not empty, as 'Validate' script of "Text1" use this:

if(event.value != "")this.getField("Text2").value = 1;

If you wish to make "Text2" back to empty if "Text1" is empty, then use this instead:

this.getField("Text2").value = event.value == "" ? "" : 1;

 

2. I don't fully understand what you wish with 'equal to not blank' +1?, can you explain please? Do you want to set it to 1 (same as first question) or add +1 to the value already in the field?

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 ,
Aug 22, 2022 Aug 22, 2022

Copy link to clipboard

Copied

Hi Nesa thank you for your reply. As I am very newbie I need to revise my question little bit.

 

1. I have a text field A and text field B.

 

If text field B is blank, text field A will be blank, else 1.

 

if (event.value != "") this.getField("Text2").value = 1; correct?

 

2. I have another text field C and text field D, and text field C will be blank if text field D is blank else Text field A +1

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 ,
Aug 22, 2022 Aug 22, 2022

Copy link to clipboard

Copied

 

You can read about writing "if" statments here:

https://acrobatusers.com/tutorials/conditional-execution/

 

You're first if is incomplete.  When writing a conditional, all conditions must be accounted for.  

 

if (event.value != "") 
    this.getField("Text2").value = 1; 
else 
    this.getField("Text2").value = "";

 

You also said the text fields were "Text A " and "Text B" then used "Text2".  And also didn't mention where this code is placed. Assuming that "Text2" is really "Text A" since that's that value being set, then this code should be in the Validation event for "Text B".  That is, according to your description.  

 

 

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
Community Expert ,
Aug 22, 2022 Aug 22, 2022

Copy link to clipboard

Copied

LATEST

1. Use the second code I gave you but use it in text field "B" as Validation script:

this.getField("A").value = event.value == "" ? "" : 1;

Make sure field name is correct.

 

2. Use this at text field "D":

var a = this.getField("A");
if(event.value == "")
this.getField("C").value = "";
else
a.value += 1;

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