JavaScript Help Needed - If either field contains specific text, then return specific text
Copy link to clipboard
Copied
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"?
Copy link to clipboard
Copied
Contain, or equal to?
Copy link to clipboard
Copied
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".
Copy link to clipboard
Copied
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")
Copy link to clipboard
Copied
Thank you, you are the best!
Copy link to clipboard
Copied
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??
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
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.

