Skip to main content
Known Participant
October 14, 2024
Answered

Need help scripting text field dependant on drop down menu but also auto-populate

  • October 14, 2024
  • 3 replies
  • 5083 views

I need help creating/scripting a text field that's dependent on a drop down menu, but also having the text field auto-populate to another text field

 

I'm really not great at scripting, and I apologise in advance I'm really dense when it comes the coding terminology, lol

 

but I've managed to workout 90% of what I need the Custom Calculate Script to do,

 

This is what I have so far:

 

if (event.value == "Option1")

{

var field1Value = this.getField("index1").value;

this.getField("text combo").value = field1Value;

}

 

 

If I type text into the “index1” field, it works good and updates the “text combo” field,

but not the other way around

 

I know if I want it to work the other way around then just swap “text combo” with “index1”

 

but I need them to both work and I don’t know how to make the script to be able to do both at the same time

 

I tried adding both of these scripts into the “Run custom Calculate script” box like this, but I couldn’t get them both to work together 😬

 

if (event.value == "Option1")

{

var field1Value = this.getField("index1").value;

this.getField("text combo").value = field1Value;

}

{

var field1Value = this.getField("text combo").value;

this.getField("index1).value = field1Value;

}

 

anyone have any ideas?

This topic has been closed for replies.
Correct answer ls_rbls

Hi there @kenth_3409 !

 

I just wanted to add my ten cents to this discussion.

 

Use the updated PDF that I am linking here for you and confirm if it works as intended : Department Dropdown

 

I've only used Mouse Up event JavaScript scripts and Custom Keystroke scripts. For example, the "index1" textfield has a Mouse Up event with the following script:

 

this.getField("Combo Box1").currentValueIndices = [1];

 

And also the following Custom Keystroke Script:

 

if(event.willCommit) this.getField("text combo").value = event.value;

 

 

Respectively, the "index2" textfiled is using a Mouse Up event with:

 

this.getField("Combo Box1").currentValueIndices = [2];

 

 And using the same Custom Keystroke Script:

 

if(event.willCommit) this.getField("text combo").value = event.value;

 

 

The intention is for index1 or index2 fields to execute a script as soon as the user starts typing in a value.

 

Such Mouse Up event script will pre-select the desired Face Value from the "Combo Box1" dropdown menu, and it will populate the "text combo" field (with the value that was typed in on those index fields),  as soon as the user hits enter.

 

Doing so, it saves time for the user; they don't need to manually drag and hover the mouse pointer over the "Combo Box1" dropdown menu to expand the list and actually select an option by click on it. 

 

In contrast to the solution offered above, the following Custom Keystroke Script is used in the "text combo" field:

 

if(event.willCommit && (this.getField("Combo Box1").value == "Option1")) {

this.getField("index1").value = event.value;
}

else if(event.willCommit && (this.getField("Combo Box1").value == "Option2")) {

this.getField("index2").value = event.value;
}

 

 

For instance, if "Combo Box1" already has an option selected (Option1 or Option2), typing in any value on this field will auto-populate its data on the corresponding index field.

 

If a user desires to switch (or perhaps, they change their mind), all they have to do is to manually select Option1 or Option2 from the dropdown menu ("Combo Box1").

 

I hope this meets your requirements. Let us know if it helped.

 

SOME REFERENCES:

 

https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/index.html

 

https://acrobatusers.com/tutorials/change_another_field/

 

https://community.adobe.com/t5/acrobat-discussions/how-do-i-show-the-selected-item-name-and-not-the-value-of-a-dropdown-box-in-another-text-box/m-p/11508340

 

 

3 replies

ls_rbls
ls_rblsCorrect answer
Community Expert
October 18, 2024

Hi there @kenth_3409 !

 

I just wanted to add my ten cents to this discussion.

 

Use the updated PDF that I am linking here for you and confirm if it works as intended : Department Dropdown

 

I've only used Mouse Up event JavaScript scripts and Custom Keystroke scripts. For example, the "index1" textfield has a Mouse Up event with the following script:

 

this.getField("Combo Box1").currentValueIndices = [1];

 

And also the following Custom Keystroke Script:

 

if(event.willCommit) this.getField("text combo").value = event.value;

 

 

Respectively, the "index2" textfiled is using a Mouse Up event with:

 

this.getField("Combo Box1").currentValueIndices = [2];

 

 And using the same Custom Keystroke Script:

 

if(event.willCommit) this.getField("text combo").value = event.value;

 

 

The intention is for index1 or index2 fields to execute a script as soon as the user starts typing in a value.

 

Such Mouse Up event script will pre-select the desired Face Value from the "Combo Box1" dropdown menu, and it will populate the "text combo" field (with the value that was typed in on those index fields),  as soon as the user hits enter.

 

Doing so, it saves time for the user; they don't need to manually drag and hover the mouse pointer over the "Combo Box1" dropdown menu to expand the list and actually select an option by click on it. 

 

In contrast to the solution offered above, the following Custom Keystroke Script is used in the "text combo" field:

 

if(event.willCommit && (this.getField("Combo Box1").value == "Option1")) {

this.getField("index1").value = event.value;
}

else if(event.willCommit && (this.getField("Combo Box1").value == "Option2")) {

this.getField("index2").value = event.value;
}

 

 

For instance, if "Combo Box1" already has an option selected (Option1 or Option2), typing in any value on this field will auto-populate its data on the corresponding index field.

 

If a user desires to switch (or perhaps, they change their mind), all they have to do is to manually select Option1 or Option2 from the dropdown menu ("Combo Box1").

 

I hope this meets your requirements. Let us know if it helped.

 

SOME REFERENCES:

 

https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/index.html

 

https://acrobatusers.com/tutorials/change_another_field/

 

https://community.adobe.com/t5/acrobat-discussions/how-do-i-show-the-selected-item-name-and-not-the-value-of-a-dropdown-box-in-another-text-box/m-p/11508340

 

 

PDF Automation Station
Community Expert
October 19, 2024

Now I finally understand what @kenth_3409 want these fields to do.  Good work.  IMO, you shouldn't use a Mouse Up action in  a text fields to change the combo box selection.  What if the user tabs into the field?  Move those scripts to On Focus actions and they will cover both scenarios (mouse click and tab into).

Known Participant
October 19, 2024

@PDF Automation Station

Is_rbls solved my question, but I still wanted to say thank you for you patience and willingness to help.

I really appreciate it and it means a lot 🙂

PDF Automation Station
Community Expert
October 14, 2024

What do you mean by "both" and "other way around"?  If the dropdown equals "Option1", you want the "text combo" field to equal the "index1" field and that is working.  Now what?

Known Participant
October 14, 2024

Hi PDF Automation Station!

 

Thanks for your reply 🙂

 

I need the text fields to auto update.

I know I can do this easily if I have multiple text fields with the same property name,

then when you type text in one, all the other text fields with the same property name will also update with whatever is typed in…

 

but I need the text field called “text combo” to also be dependent on the dropdown/combo box menu (option1, option2, etc)

 

so I used the first script I mentioned in my post.

 

when I type in the text field called “index1” it updates the dependent text field called “text combo” when “option1” is selected

which is what I want,

 

but I also need the text field called “index1” to update when I type in the text field called “text combo” when “option1” is selected from the dropdown menu.

 

Sorry, I’m bad at explaining things, lol

PDF Automation Station
Community Expert
October 14, 2024

I sounds like what you want it going to create an infinite loop - the only way out of which is to do a hard shut down of Adobe.  Can you upload a form with only the affected fields and describe exactly what you want to happen?

try67
Community Expert
October 14, 2024

Your description doesn't make much sense, I'm afraid. You want to copy field1 to field2 and then field2 to field1? What's the point of the latter action? The first one already guarantees they will have the same value. The second action doesn't do anything.

Known Participant
October 14, 2024

Hi try67!

 

Thanks for your reply 🙂

 

I need the text fields to auto update.

I know I can do this easily if I have multiple text fields with the same property name,

then when you type text in one, all the other text fields with the same property name will also update with whatever is typed in…

 

but I need the text field called “text combo” to also be dependent on the dropdown/combo box menu (option1, option2, etc)

 

so I used the first script I mentioned in my post.

 

 

when I type in the text field called “index1” it updates the dependent text field called “text combo” when “option1” is selected

which is what I want,

 

but I also need the text field called “index1” to update when I type in the text field called “text combo” when “option1” is selected from the dropdown menu.

 

Sorry, I’m bad at explaining things, lol

try67
Community Expert
October 14, 2024

I'm sorry, I don't follow. Your last two sentences ("when I type..." and "but I also...") are describing the same thing, as far as I can see.