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

JavaScript Help Needed - If either field contains specific text, then return specific text

Explorer ,
May 03, 2023 May 03, 2023

Hello...

I am trying to fix the below JavaScript to reference 2 fields:

 

var t1 = this.getField("TextField1").valueAsString;
if (t1=="RR") event.value = "10 Months";
else event.value = "";

 

How do I update this so that if TextField1 or TextField2 contain "RR", then TextField3 populates "10 Months"?

 

TOPICS
JavaScript , PDF , PDF forms
3.0K
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 ,
May 03, 2023 May 03, 2023

Contain, or equal to?

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
Explorer ,
May 04, 2023 May 04, 2023

Hello...  i wouldnt mind know how to utilize contains or equal to.  The problem I am really trying to solve is how to look in more than 1 field for the "RR".

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 ,
May 04, 2023 May 04, 2023

To check for field1 or field 2 use 'or' ||

var t1 = this.getField("TextField1").valueAsString;
var t2 = this.getField("TextField2").valueAsString;
if (t1=="RR" || t2 == "RR")

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
Explorer ,
May 04, 2023 May 04, 2023

Thank you, you are the best!

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
Explorer ,
May 10, 2023 May 10, 2023

Hello Again...  I ran across a slight issue.  The javascript worked as expected when one of the text fields included RR however the script does not work if one of the 2 cells includes text other than RR.  My document had RR in TextField1 and KH in TextField2, and "10 months" did not populate.  Any ideas??

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 ,
May 10, 2023 May 10, 2023

It should have worked in that scenario. Are you sure the first field's value is exactly "RR"? If it's anything else, like "RR " (with a space) or "rr", it won't work.

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 ,
May 10, 2023 May 10, 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
Explorer ,
May 11, 2023 May 11, 2023
LATEST

You are correct, the script works properly if I delete KH and add it back in.  It does not work when the form is populated with KH in the textfield until after I update the field again.

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