Skip to main content
New Participant
August 14, 2020
Answered

Dynamic text from a drop-down list does not update.

  • August 14, 2020
  • 1 reply
  • 3304 views

First of all forgive my English, it is not my native language. I'm having a problem with automatically filling out a form field from a drop-down list.

I have a drop-down list named "Options" and form fields named "name", "age" and "text".

I would like that from the option chosen in my drop-down list the name form field "text" would be filled with a predefined text using the values ​​contained in the fields "name" and "age".

I managed to do this, however when I replace the values ​​in the "name" and "age" fields and change the option in my drop-down list, the text in the "text" field is not updated and always uses the information from the previous choice.

I am not a programmer, just a curious person trying to improve processes in my job. Here's the step-by-step of what I did:

 

1st. I formatted the drop-down list so that when no option is selected, the "text" field is blank.

if( event.willCommit ) { 
    if(event.value == "") this.resetForm(["text"]); else 
textscript(event.value); 
}

2nd. I created a script so that when I make a choice from the drop-down list, the "text" field is filled with the script's information.

// Placing all pre-population data in a single data structure 
var textscripting = { "Option 1":{ story: "The funny " + this.getField("name").value + ", " + this.getField("age").value + ", was at Mom's house."},
"Option 2":{ story: "Mischievous " + this.getField("name").value + ", " + this.getField("age").value + ", went to Grandma's."},
"Option 3":{ story: "Ricky " + this.getField("name").value + ", " + this.getField("age").value + ", went to Daddy's house."},


}; 
function textscript(cCharactherName) { 
    // Filling in fields with values ​​of the previously defined objects 
    this.getField("text").value = textscripting[cCharactherName].story; 
    
  
}

 

So the intention is that when I choose option 1, the field "name" is "John", the field "age" is "20", the field "text" will bring me: "The funny John, 20, was at Mom's house." 

It turns out that when I change John's name to Doc, for example, the options don't have Doc's name in their texts, but they still use John's name.

 

I would be immensely grateful if you can help me. I'm attaching the file so they can see more clearly what I wanted to say. Greetings from Brazil.

This topic has been closed for replies.
Correct answer ls_rbls

Hello, ls_rbls!

Thank you very much for your cooperation, it really works. I had thought of something like this, however there is a catch: this way there is no way for us to edit the "text" form field after a choice made in the drop-down list. The final intention of this form that I am preparing is that the final text is a medical report and has a part that is standard and I want to leave the field cleared for future editions. Thom Parker's script allows me to do just that, make edits after a choice is made in the drop-down list. I really think there is some code that we could use so that the document-level script is updated with each choice we make in the drop-down list. Unfortunately, my programming knowledge doesn't allow me to go any further, despite a lot of research done.

 

Thanks again for your time and collaboration.

I will use your script for another purpose, with a text that does not need to be edited later.


Yes, you're welcome.  Just to be clear I am not a programmer either. I follow some developers in these forums and learn from their guidance.

 

If you want my script to behave like the document-level script all you have to do is remove this line:

 

event.value =" ";

 

That was my mistake. I had it there because I was unsure if this is what you wanted.

 

When you remove that entry , this script will behave in the same way as Thom Parker's document-level script; it will change once you select a different option from the combobox.

 

NOTE: I am still figuring out why the original  scrfipt breaks. I will post back again.

 

1 reply

ls_rbls
Adobe Expert
August 15, 2020

Hi,

 

If the script is not working wher did you place the funtion ?  Is it a document level script?

 

 Where are you placing these scripts?

 

The other thing is that I noticed  that you may need to use this line instead event.value ="";   (I least I prefer to use this option instead of the resetForm() method).

 

If you use the resetForm() method you must manually set the default value in the drop down menu (like an empty space) .

 

When you 're editing the dropdown fields select the empty line entry and  close the field properties dialogue box. The last value that you select here before you close the field porperties dialogue box will remain as the default value.

 

You also need to un-tick the box that allows users to enter custom text, and also check the box " Commit selected value immediately".

 

See slide:

 

 

And is this part a custom key stroke script?

if( event.willCommit ) { 
    if(event.value == "") this.resetForm(["text"]); else 
textscript(event.value); 
}

 

I think that it should be phrased to something like this:

 

if(event.willCommit ) { 
    if(event.value != "") {
// call for the function here...

} else {

this.resetForm(["text"]);

/// or use event.value ="";
  }
}

 

But my main question is : where did you get this script from ? What is the reference?

 

 

New Participant
August 15, 2020

Hello! First of all thanks for the help.

Answering your question:

And is this part a custom key stroke script?

Yes, this is.

 

The second script is at the document level.

 

I liked your idea to reset the "text" field when there is no option chosen from the drop-down list. But my problem is to form a text from a choice in the drop-down list. The text will use the information contained in other form fields, in which case it will be the form fields "name" and "age".

 

where did you get this script from ? What is the reference?

 

The script was based on this one >> https://acrobatusers.com/tutorials/change_another_field/  . It works if we want to fill a form field with pre-defined text in a document-level script based on a choice made from a drop-down list. But when I insert this.getField ("xxx") in this predefined text, it only works for the first choice made in the drop-down list. When I make another choice, the field containing the text does not update with the new value of this.getField ("xxx").

ls_rbls
ls_rblsCorrect answer
Adobe Expert
August 16, 2020

Hello, ls_rbls!

Thank you very much for your cooperation, it really works. I had thought of something like this, however there is a catch: this way there is no way for us to edit the "text" form field after a choice made in the drop-down list. The final intention of this form that I am preparing is that the final text is a medical report and has a part that is standard and I want to leave the field cleared for future editions. Thom Parker's script allows me to do just that, make edits after a choice is made in the drop-down list. I really think there is some code that we could use so that the document-level script is updated with each choice we make in the drop-down list. Unfortunately, my programming knowledge doesn't allow me to go any further, despite a lot of research done.

 

Thanks again for your time and collaboration.

I will use your script for another purpose, with a text that does not need to be edited later.


Yes, you're welcome.  Just to be clear I am not a programmer either. I follow some developers in these forums and learn from their guidance.

 

If you want my script to behave like the document-level script all you have to do is remove this line:

 

event.value =" ";

 

That was my mistake. I had it there because I was unsure if this is what you wanted.

 

When you remove that entry , this script will behave in the same way as Thom Parker's document-level script; it will change once you select a different option from the combobox.

 

NOTE: I am still figuring out why the original  scrfipt breaks. I will post back again.