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

How to assign a value depending on an input field?

Contributor ,
Jun 14, 2021 Jun 14, 2021

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.

TOPICS
How to , PDF forms

Views

2.8K

Translate

Translate

Report

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

correct answers 2 Correct answers

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"

Votes

Translate

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

Votes

Translate

Translate
Community Expert ,
Jun 14, 2021 Jun 14, 2021

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

Votes

Translate

Translate

Report

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

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

 

 

Votes

Translate

Translate

Report

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

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

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

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"

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Thank you Nesa!

 

Appreciate the help.

Votes

Translate

Translate

Report

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

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.

Votes

Translate

Translate

Report

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

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

Thanks Nesa! The scripts works perfectly.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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. 

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

See above.

Votes

Translate

Translate

Report

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