Skip to main content
Known Participant
November 4, 2020
Question

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

  • November 4, 2020
  • 1 reply
  • 801 views

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.

 

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
November 4, 2020

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?

KYJudAuthor
Known Participant
November 4, 2020

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.

try67
Community Expert
Community Expert
November 4, 2020

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;