Copy link to clipboard
Copied
Thanks in advance for everyone's help. I'm using Pro 11.
I'm creating a document template where I need certain textboxes to change based on whether a specific box contains certain text, but where there is still other text in the box. For example, if the primary textbox contains "2019-PR-123" I would like a separate box to return "Product", but if the box contains "2019-LM-123" I would like the separate box to return "Labor". But I want the return values to be only based on whether the primary box contains the "PR" or "LM" irrespective of what the other numbers are.
I've searched and searched and can't seem to find a simple way to do this. And I'm easily able to achieve the result of the primary textbox contains only the "PR" or "LM" using an if/then based on the value of the primary box, but I need it to do an if/then based not on the value of the box but whether the box includes certain text within the large text.
This kind of thing is usually done using a Regular Expression.
You can use this code as the custom calculation script of the second text field:
var s = this.getField("Text1").valueAsString; // insert actual field name
if (/PR/.test(s)) event.value = "Product";
else if (/LM/.test(s)) event.value = "Labor";
else event.value = "";
Copy link to clipboard
Copied
This kind of thing is usually done using a Regular Expression.
You can use this code as the custom calculation script of the second text field:
var s = this.getField("Text1").valueAsString; // insert actual field name
if (/PR/.test(s)) event.value = "Product";
else if (/LM/.test(s)) event.value = "Labor";
else event.value = "";
Copy link to clipboard
Copied
This exactly what I needed, thank you. I think my two problems was that I wasn't using valueAsString for the source textbox, and I didn't realize you could do a /RegEx/.test(s), I kept incorrectly trying to do the test as a standalone function.