• 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 reset a text field based on a drop down selection

Explorer ,
Apr 05, 2021 Apr 05, 2021

Copy link to clipboard

Copied

Is there a way to reset (clear entered data) when a drop down selection is changed? I have a form that has different form fields display based on the drop down selection. 

For example: 

If  Drop down selection= "dd1"

Then Text boxes "Text 1" and "Text 2" are visable and "Text 3" and "Text 4" are hidden

 

If Drop down selection= "dd2"       

Then Text boxes "Text 3" and "Text 4" are visable and "Text 1" and "Text 2" are hidden

 

The values of "Text 1" and "Text 2" OR "Text 3" and "Text 4" need to populate in two text fields at the end of the form. The problem that I am having is that if someone first selects "dd1" and fills out "Text 1" and "Text 2" and then changes their mind and changes their selection to "dd2", and enters new values for the now corresponding "Text 3" and "Text 4", the populated value for the two text fields at the end of the form still show the values for "Text 1" and "Text 2" because the text fields are hidden when the new selection is made, but not cleared. Any help would be appreciated!

 

TOPICS
General troubleshooting , How to , JavaScript , PDF forms

Views

3.3K

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 , Apr 05, 2021 Apr 05, 2021

Two fields at the end of the form I assume field1 populate from text1 and text3 and field 2 populate from text 2 and text4 fields?

You can use this script as Validation of dropdown field:

if(event.value == "dd1"){
this.getField("Field1").value = this.getField("Text1").value;
this.getField("Field2").value = this.getField("Text2").value;}
else if( event.value == "dd2"){
this.getField("Field1").value = this.getField("Text3").value;
this.getField("Field2").value = this.getField("Text4").value;}
else {
this.g

...

Votes

Translate

Translate
Community Expert , Apr 06, 2021 Apr 06, 2021

Yes, move script to calculate.

Votes

Translate

Translate
Adobe Employee ,
Apr 05, 2021 Apr 05, 2021

Copy link to clipboard

Copied

Hi there

 

Hope you are doing well and sorry for the trouble. As described, you want to reset the text field based on the drop down selection.

 

The workflow that you are trying to achieve is possible using the JavaScript. For more information about using JavaScript please check out the help page: https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/js_developer_guide.pdf

 

Hope it will help

 

Regards

Amal

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 ,
Apr 05, 2021 Apr 05, 2021

Copy link to clipboard

Copied

You can a test if using a  custom calculation script in the dropdown field works for you, like for example:

 

if (event.valueAsString == "dd1") {

this.getField("Text1").display = display.visible;

 

this.getField("Text2").display = display.visible;

 

this.getField("Text3").display = display.hidden

 

this.getField("Text4").display = display.hidden

 

this.resetForm(["Text3", "Text4"]);

 

else if (event.valueAsString == "dd2") {

 

this.getField("Text3").display = display.visible;

 

this.getField("Text4").display = display.visible;

 

this.getField("Text1").display = display.hidden;

 

this.getField("Text2").display = display.hidden;

 

this.resetForm(["Text1", "Text2"]);

 

}

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 ,
Apr 05, 2021 Apr 05, 2021

Copy link to clipboard

Copied

Two fields at the end of the form I assume field1 populate from text1 and text3 and field 2 populate from text 2 and text4 fields?

You can use this script as Validation of dropdown field:

if(event.value == "dd1"){
this.getField("Field1").value = this.getField("Text1").value;
this.getField("Field2").value = this.getField("Text2").value;}
else if( event.value == "dd2"){
this.getField("Field1").value = this.getField("Text3").value;
this.getField("Field2").value = this.getField("Text4").value;}
else {
this.getField("Field1").value = "";
this.getField("Field2").value = "";}

Rename fields as needed.

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
Explorer ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

Thanks Nesa! This looks exactly like what I am looking for. Unfortunately, it doesn't seem to be working. I added it to the bottom of my current validation script for the drop down that enables the form fields ("Text1" "Text2" "Text3" "Text4") to be visible or hidden. I'm wondering if the issue is with the fact that I am using groups in the earlier script because more that just "Text1" and "Text2"  OR "Text3" and "Text4" need to be hidden or visible based on the dropdown selection.

 

Here's the current dropdown validation script (incorporating your script at the bottom): 

if(event.value =="dd1"||event.value =="dd2") {

this.getField("Hide.Names").display = display.hidden;

} else {
this.getField("Hide.Names").display = display.visible;
}

if(event.value =="dd1") {

this.getField("TEXTA").display = display.visible;

} else {
this.getField("TEXTA").display = display.hidden;
}

if(event.value =="dd2") {

this.getField("TEXTB").display = display.visible;

} else {
this.getField("TEXTB").display = display.hidden;
}

if(event.value == "dd1"){
this.getField("Print Name1").value = this.getField("TEXTA.Text1").value;
this.getField("Print Name2").value = this.getField("TEXTA.Text2").value;}
else if( event.value == "Revocable"){
this.getField("Print Name1").value = this.getField("TEXTB.Text1").value;
this.getField("Print Name2").value = this.getField("TEXTB.Text2").value;}
else {
this.getField("Print Name1").value = "";
this.getField("Print Name2").value = "";}

 

Note:

"Hide.Names" is just a white text box that hides the information if no selection or another dd selection is made 

"TEXTA" group contains "Text1" and "Text2", plus two additional fields

"TEXTB" group contains "Text3" and "Text4", plus two additional fields

The actual field names have been modified for this correspondence.

 

Could the reason that the bottom portion of the script is not working be because of the group field names? I don't know much about JavaScript, but I know that a very small change can make a big difference. Thanks for all your time and assistance!

 

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 ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

What exactly isn't working?

You set code so when dd2 is selected field TEXTB is visible othervise it's hidden and you set when value is "Revocable", "Print Name1" and "Print Name2" should be TEXTB value but at this point TEXTB is hidden but it will still show value. Is that intentional?

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
Explorer ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

Sorry, that was an oversight in renaming the actual fields for this correspondance. "Revocable" = "dd2".

 

What is not working is that the form fields  ("Print Name1" "Print Name2" "Print Name3" "Print Name4") are not populating with the text enterered in the corresponding fields ("TEXTA.Text1" "TEXTA.Text2" "TEXTB.Text1" "TEXTB.Text2". And, since they are not populating, I also can't tell if  the field is being reset if another dd is selected. Does that make sense?

 

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 ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

I tried to recreate your fields from your info and your code is working fine for me.

Try checking all fields are named correctly and also did you check " Commit selected value immediately" in dropdown field options tab?

It would be best if you could share your file so I can see what is going on.

 

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
Explorer ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

I do have " Commit selected value immediately" in dropdown field options tab checked. I've been checking and double checking the fields names against the field names in the script and have not been able to find any differences/issues. Unfortunately, I can't share my file, since it has confidential client information. I'm thinking about putting dummy pages behind the fillable fields, but I don't know if that would be too confusing. Do you think that would be viable option?  I have never shared a file before, how does that work?

 

Thank you again for all your time and 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
Community Expert ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

You can upload file to site like google drive...etc here is file I created, take a look and see if it's similar to what you need.

https://drive.google.com/uc?export=download&id=19wPNBPgN4vwYG9JZ-jLesWOJnfVETZzA 

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
Explorer ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

That is very close. I was able to see the issues by using your file rather than mine, because all the fields are on one page. I now see that the original script is working, BUT the fields don't populate until after the drop down is reselected after the corresponding fields ("TEXTA.Text1" "TEXTA.Text2" "TEXTB.Text1" "TEXTB.Text2") are filled in. The user would not have any reason to go back to the drop down after the corresponding fields are filled, unless they made a mistake. Ideally, how the form would work is:

 

  1.  On page 1 of form, user would make a drop down selection ("dd1""dd2""ddOther") and the appropriate text boxes would appear ("TEXTA.Text1"and "TEXTA.Text2"OR"TEXTB.Text1"and"TEXTB.Text2")
  2. User fills in the text boxes that have appeared and continues forward filling out the form.
  3. At the end of the form (in this case, p.5), the corresponding text boxes ("Print Name1" and "Print Name2" would be populated with the previously entered values.

 

Is there a way to make the corresponding text box fill without going back and toggling the drop down selection?

 

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 ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

Yes, move script to calculate.

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
Explorer ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

In the drop down?

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 ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

Yes, that should change field values whenever something is changed in form, opposite to validation where once value is selected from dropdown it wouldn't update fields until another value is selected.

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 ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

Or you can create validation script for TEXTA.Text1...etc fields like this:

this.getField("Print Name1").value = event.value;

and add in your dropdown script to reset value of TEXTA.Text1 fields when hidden like this:

https://drive.google.com/uc?export=download&id=11UtpuwG7QDVjELTQolk1W5TlUJ3EwCPc 

 

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
Explorer ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

That worked!!!! Thank you SO much! Are you available for paid consulting services?

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 ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

Yes, I am.

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
Explorer ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

What's your rate and how would I get in touch with 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 ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

LATEST

You can contact me at [moderator removed e-mail address]

 

 

[moderator: please use private message to contact Nesa]

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