Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


How to assign a value depending on an input field?

Explorer ,
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

1.0K

Likes

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

Adobe Community Professional , 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"

Likes

Translate

Translate
Adobe Community Professional , 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.

Likes

Translate

Translate
Adobe Community Professional ,
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";}

Likes

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

 

 

Likes

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
Adobe Community Professional ,
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.

Likes

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
Explorer ,
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?

Likes

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
Adobe Community Professional ,
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"

Likes

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

Copy link to clipboard

Copied

Thank you Nesa!

 

Appreciate the help.

Likes

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
Explorer ,
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.

Likes

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
Adobe Community Professional ,
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.

Likes

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

Copy link to clipboard

Copied

LATEST

Thanks Nesa! The scripts works perfectly.

Likes

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
Adobe Community Professional ,
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?

Likes

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
Explorer ,
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. 

Likes

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

Copy link to clipboard

Copied

See above.

Likes

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