Skip to main content
Sonny AR
Inspiring
September 6, 2024
Answered

Populate Text field from dropdown but text field remain editable.

  • September 6, 2024
  • 3 replies
  • 614 views

Hello Experts,

 

I have two dropdowns ('Dropdown3' and 'Dropdown4') and a text field ('comments'). I am using JavaScript in custom calculations of comment field to populate the 'Comments' field based on the dropdown selections, which is working perfectly.

 

However, when I manually enter additional text in the 'comments' field and then make another selection in the form, the newly entered text is automatically wiped out.

I want to preserve any manually entered text in the 'comments' field.

 

TIA

This topic has been closed for replies.
Correct answer Nesa Nurani

Use this:

if (event.source && (event.source.name=="Dropdown3" || event.source.name=="Dropdown4")) {
//put your script between these curly brackets
};

3 replies

Thom Parker
Community Expert
Community Expert
September 6, 2024

To be clear, you are building the value of a text field from two dropdowns. But you also want the user to be able to enter data.  

1) Does the user entered data completely replace the dropdown data?  So that new selections do not change the combined text after a custom user entry? 

2) Or do you want the dropdown selections to modify the combined text, and maintain the user input?

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
PDF Automation Station
Community Expert
Community Expert
September 6, 2024

Calculation scripts run every time any field value changes, so the end user can't enter any text without the value reverting to the calculated value.  Validation scripts, on the other had, only run when the value of the field containing the validation script changes.  In this case the validation scripts should be in the two dropdowns.  But since you have export values as well as display values in the dropdowns, it's easier to use a custom keystroke script.  These articles explain it all:

https://pdfautomationstation.substack.com/p/calculation-vs-validation-scripts

https://pdfautomationstation.substack.com/p/calculation-vs-validation-scripts-eb5

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
September 6, 2024

Use this:

if (event.source && (event.source.name=="Dropdown3" || event.source.name=="Dropdown4")) {
//put your script between these curly brackets
};
Sonny AR
Sonny ARAuthor
Inspiring
September 6, 2024

Its worked!

But is there a way to preserve the input text even when selecting from another dropdown? It still resets the input value after making a selection from 'Dropdown4'.

PDF Automation Station
Community Expert
Community Expert
September 6, 2024
if (event.source && event.source.name=="Dropdown3")
{
//your script
}