Skip to main content
Participant
Jan 29, 2025 9:50 PM UTC
Question

Text Field changes when dropdown option changes

Hello all,

 

I've done some hunting, but I can't seem to find answer for my question. (If it's been answered elsewhere, I'd appreciate a link).

 

I'm working on a PDF with dropdown menus that determine the text in corresponding text fields. For all but the first field, it is working correctly. If it the dropdown menu is blank, the text field is blank. If the dropdown option moves to 2, the text field changes to .25. When the dropdown changes back to blank, the text field changes back to blank.

 

For all except the very first box. For each dropdown box, I've set up the custom calculation script as follows (direclty copied):

var f = this.getField("Score5");
if(event.value == "1")
f.value = ".0";
else if(event.value == "2")
f.value = ".25";
else if(event.value == "3")
f.value = ".50";
else if(event.value == "4")
f.value = ".75";
else if(event.value == "5")
f.value = "1.00";
else if(event.value == " ")
f.value = "";

 

I also have the "Commit selected value immediately" set for all dropdown boxes. 

 

Here is the direct copy for the first dropdown box:

var f = this.getField("Score1");
if(event.value == "1")
f.value = ".0";
else if(event.value == "2")
f.value = ".25";
else if(event.value == "3")
f.value = ".50";
else if(event.value == "4")
f.value = ".75";
else if(event.value == "5")
f.value = "1.00";
else if(event.value == " ")
f.value = "";

 

I'm not sure where I went wrong with just DropDown1 that it does not update Score1 text field when the blank option is set. I've attached a short video showing the issue.

 

Help?

2 replies

Nesa Nurani
Community Expert
Community Expert
Jan 30, 2025 5:40 AM UTC

It would be best to share the actual file so we can see where is the issue.

Check that default condition is " ".

The condition for "1" is unnecessary, since it set percentage to 0.

Translate
JR Boulay
Community Expert
Community Expert
Jan 29, 2025 10:11 PM UTC

Using calculation in this case is not a good practice.

You should use event.willCommit and event.change in Format : Keystroke script (More info here: https://www.pdfscripting.com/public/Formatting-Form-Fields.cfm).

See attachment.

 

 

 

var f = this.getField("Score5");
if (!event.willCommit) {
if(event.change == "1")
f.value = ".0";
else if(event.change == "2")
f.value = ".25";
else if(event.change == "3")
f.value = ".50";
else if(event.change == "4")
f.value = ".75";
else if(event.change == "5")
f.value = "1.00";
else if(event.change == " ")
f.value = "";
}

 

 

 

Translate
Acrobate du PDF, InDesigner et Photoshopographe