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

How to assign a value depending on an input field?

Contributor ,
Jun 14, 2021 Jun 14, 2021

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.

TOPICS
How to , PDF forms
4.8K
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
2 ACCEPTED SOLUTIONS
Community Expert ,
Jun 18, 2021 Jun 18, 2021

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"

View solution in original post

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 ,
Jun 19, 2021 Jun 19, 2021

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.

View solution in original post

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 ,
Jun 14, 2021 Jun 14, 2021

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";}

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
Contributor ,
Jun 15, 2021 Jun 15, 2021

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".

 

 

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 ,
Jun 15, 2021 Jun 15, 2021

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.

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
Contributor ,
Jun 18, 2021 Jun 18, 2021

Hello Nesa,

 

Apology for my ignorance.

 

I have attached here a sample.

 

Which PDF field should I insert the script you have provided? And should I insert it in Validate, Run custom validation script or Calculate, Custom calculation script?

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 ,
Jun 18, 2021 Jun 18, 2021

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"

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
Contributor ,
Jun 19, 2021 Jun 19, 2021

Thank you Nesa!

 

Appreciate the help.

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
Contributor ,
Jun 19, 2021 Jun 19, 2021

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.

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 ,
Jun 19, 2021 Jun 19, 2021

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.

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
Contributor ,
Jun 21, 2021 Jun 21, 2021
LATEST

Thanks Nesa! The scripts works perfectly.

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 ,
Jun 15, 2021 Jun 15, 2021

Why not keep it gender-neutral? Or let people decide for themselves what pronouns to use?

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
Contributor ,
Jun 15, 2021 Jun 15, 2021
Hello!
Thank you for replying.
However, this is not my document and the requirements is specified by my client.
I hope there is a solution. 
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 ,
Jun 15, 2021 Jun 15, 2021

See above.

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