Copy link to clipboard
Copied
Hi... I am new to Java and Adobe. I searched posts and could not find the answer.
I am trying to create a document with fields that automatically populate specific responses.
Example:
If TextField1 equals "Apples", TextField2 populates "Fruit"
If TextField1 equals "Steak", TextField2 populates "Meat"
If TextField1 equals "Crackers" "Chips" or "Nuts", TextField2 populates "Snack"
Are there any Java geniuses out there that can help out a rookie?
You can use this code as the custom calculation script of TextField2:
var t1 = this.getField("TextField1").valueAsString;
if (t1=="Apples") event.value = "Fruit";
else if (t1=="Steak") event.value = "Meat";
else if (t1=="Crackers" || t1=="Chips" || t1== "Nuts") event.value = "Snack";
else event.value = "";
PS. For future reference, this is JavaScript, not Java.
Sure. Either:
if (/ham/i.test(t1)) ...
Or:
if (t1.toLowerCase().indexOf("ham")!=-1) ...
Add 'i' for case insensitive.
Example form above code:
(/ham/i.test(t1))
Copy link to clipboard
Copied
You can use this code as the custom calculation script of TextField2:
var t1 = this.getField("TextField1").valueAsString;
if (t1=="Apples") event.value = "Fruit";
else if (t1=="Steak") event.value = "Meat";
else if (t1=="Crackers" || t1=="Chips" || t1== "Nuts") event.value = "Snack";
else event.value = "";
PS. For future reference, this is JavaScript, not Java.
Copy link to clipboard
Copied
Thank you very much TRY67!! I really appreciate.
Copy link to clipboard
Copied
How would you modify this to look for a word in a sentence, for example, "My favourite foods are ham and steak.", how would you check to see if the word "ham" is within the string?
Copy link to clipboard
Copied
if (/ham/.test(t1)) ...
Copy link to clipboard
Copied
Thank you very much!
Copy link to clipboard
Copied
If you're going to search for texts with punctuations, though, then use this method:
if (t1.indexOf("ham")!=-1) ...
Copy link to clipboard
Copied
Is there I way I can change this formula so the text I am searching for is not case sensative?
Copy link to clipboard
Copied
Sure. Either:
if (/ham/i.test(t1)) ...
Or:
if (t1.toLowerCase().indexOf("ham")!=-1) ...
Copy link to clipboard
Copied
Add 'i' for case insensitive.
Example form above code:
(/ham/i.test(t1))