Copy link to clipboard
Copied
Good day!
I have a PDF form with an input field "Gender"
In the body of the form, I wish to replace a variable fields depending on the Gender value.
If Gender is "Male", I wish to assign "him", "he" or "his"
If Gender is "Female", I wish to assign "her", "she" or "her"
Thank you in advance for any help extended.
Here is your file with code inside for you to test it:
https://drive.google.com/uc?export=download&id=1_Df-FHBWn1m8_Vvunq4_G_9CYAOraPdk
Code is in "Gender" field in "Validation" tab as "Run custom validation script"
Then you would need to put script in custom calculation of each field:
if(this.getField("Gender").valueAsString == "Male")
event.value = "he";
else if(this.getField("Gender").valueAsString == "Female")
event.value = "she";
else event.value = "";
Replace he/she for other fields everything else is same.
Copy link to clipboard
Copied
I assume you have different fields for each value so here is sample script you can easily adapt,use it at "Gender" field as validation script:
var f1 = this.getField("Text1");
var f2 = this.getField("Text2");
var f3 = this.getField("Text3");
if(event.value == "Male"){
f1.value = "him";
f2.value = "he";
f3.value = "his";}
else if(event.value == "Female"){
f1.value = "her";
f2.value = "she";
f3.value = "her";}
Copy link to clipboard
Copied
Thank you Nesa for this solution. What simple script that I can use for this examples:
Input Fields are:
Name
Gender
Sample sentences:
The teacher call <Field1> to go to the backboard.
I want to replace <Field1> to him or her depending on the Gender. If the Gender = Male, Field1 will be repleaced by "him". Otherwise, it will be "her".
Copy link to clipboard
Copied
Like I posted above you can easily adapt code, so for only that one field it would be:
var f1 = this.getField("Field1");
if(event.value == "Male")
f1.value = "him";
else if(event.value == "Female")
f1.value = "her";
Code is placed in "Gender" field as validation script.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Here is your file with code inside for you to test it:
https://drive.google.com/uc?export=download&id=1_Df-FHBWn1m8_Vvunq4_G_9CYAOraPdk
Code is in "Gender" field in "Validation" tab as "Run custom validation script"
Copy link to clipboard
Copied
Thank you Nesa!
Appreciate the help.
Copy link to clipboard
Copied
Nesa,
Just thinking. What would be the script if I want the script to be in Field1, Field2 and Field3 in the same file I have attached depeding on the input entered in Gender?
Is this possible? Thank you.
Copy link to clipboard
Copied
Then you would need to put script in custom calculation of each field:
if(this.getField("Gender").valueAsString == "Male")
event.value = "he";
else if(this.getField("Gender").valueAsString == "Female")
event.value = "she";
else event.value = "";
Replace he/she for other fields everything else is same.
Copy link to clipboard
Copied
Thanks Nesa! The scripts works perfectly.
Copy link to clipboard
Copied
Why not keep it gender-neutral? Or let people decide for themselves what pronouns to use?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
See above.