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

button to make an already automatically filled field go blank so that user can type in new info

Community Beginner ,
Nov 04, 2020 Nov 04, 2020

Copy link to clipboard

Copied

I have a multi-page form that requires the user's name in numerous blanks. I have named all such fields  the same (“Name”) so that when the user fills in the first field all the others are also filled in. However, there is one such blank down in the pack where the user might very occasionally want to  leave the field blank or type in different information.

 

I am new to this, but I have created a button the user can hit and make the one selected field go blank, allowing the user to then either leave it blank or type in  new information, without effecting the other fields.

 

To do this I have cobbled together the following code:

 

  1. I changed name of  the field to be made changeable from “Name” to “Name1”
  2. I created a field named “Hidden” that has a display of “Hidden”
  3. I put the following JavaScript in the calculate tab of “Name1”

 

if (this.getField

("Hidden").value.length== 0)

event.value = this.getField("Name").valueAsString

 

4. In the actions tab of the button I put the following two scripts

a)

this.getField

("Hidden").value

=

"Hidden"

 

b)

this.resetForm("Name1")

 

Surely to goodness there is a simpler, more straight forward way to do this. What is it? It's bothering me.

 

Thank you very, very much in advance for your assistance.

 

TOPICS
Acrobat SDK and JavaScript

Views

543

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 ,
Nov 04, 2020 Nov 04, 2020

Copy link to clipboard

Copied

You have to give it a different name, like Name1. You also have to think about how it's going to work.

For example, if the user enters something into Name, should it populate Name1 automatically? What about if Name1 already has a value? Should it overwrite it, or not?

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 Beginner ,
Nov 04, 2020 Nov 04, 2020

Copy link to clipboard

Copied

I did give it a different name, and in fact used, "Name1."  I want "Name1" to be populated automaticlly when the other "Name" fields are filled in  so that unless the user hits the button the "Name1" field  acts as if it were a "Name" field.

 

Using the code I developed,   the "Name1" field cannot be overwritten manually. If you go in and delete what was previously put in automatically (and either write somehing new or leave it blank) the original information returns when you leave the field.

 

 I had not thought about overwriting what's automatically there. Upon further thought  I would prefer that the user not be able to change the field manually, as it might encourage the user to try the same thing  on another "Name" field  and that would change  all the "Name" fields.

 

When the user hits the button, the "Name1" field  goes blank and acts afterwards as if were a brand new totally new and separate empty field. Until that happens the "Name1" field acts is as if it were just another "Name" field.

 

Thank you very much for your attention.

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 ,
Nov 04, 2020 Nov 04, 2020

Copy link to clipboard

Copied

Remove the code you added and add the following as the custom Validation script of Name:

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

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 Beginner ,
Nov 04, 2020 Nov 04, 2020

Copy link to clipboard

Copied

Thanks, but you're above my pay grade. I built a simple one page sample and moved the code all over the place. I'll just let the issue pass, stick with my clumbsy method, and get out of your hair.

 

Thanks again. Stay safe.

 

 

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 ,
Nov 04, 2020 Nov 04, 2020

Copy link to clipboard

Copied

LATEST

All you had to do was copy the code I provided, but OK...

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