Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
2

Drop Down to Fill Text Box

Community Beginner ,
Jun 06, 2023 Jun 06, 2023

I am trying to create an order form in Acrobat Pro. 

 

I need a drop down box with three choices, I have placed four choices with two spaces being the default choice. I have given all four choices export values of 0, 1, 2, and 3 respective of how they appear as choices in the drop down box. I am trying to populate a text box directly under the drop down box with instructions based on which choice is picked in the drop down box. I have chosen Commit selected value immediately for the Option in the drop down box.  I am a bit confused under the Add an Action portion. Do I want mouse Up, Down, Enter, Exit....

 

I have it set now for Mouse Enter and Run a JavaScript

 

and here is my code:

 

(function () {
if (!event.willCommit) {
// Set up an array of options. \r = carriage return
var aInst = [];
aInst[0] = "";
aInst[1] = "Starting Dose (Weeks 1-12) \rInstructions: \rStep 1: INJECT 0.25mg (0.05mls OR 5u on syringe) SQ ONCE A WEEK FOR 4 WEEKS. \rStep 2: INJECT 0.5mg (0.1mls OR 10u on syringe) SQ ONCE A WEEK FOR 4 WEEKS. \rStep 3: INJECT 1mg (0.2mls OR 20u on syringe) SQ ONCE A WEEK FOR 4 WEEKS.";
aInst[2] = "Second Dose (Weeks 13-17) \rInstructions:\rStep 1: INJECT 1.7mg (0.35mls OR 35u on syringe) SQ ONCE A WEEK FOR 4 WEEKS.\rStep 2: INJECT 2.4mg (0.5mls OR 50u on syringe) SQ ONCE WEEKLY THEREAFTER.";
aInst[3] = "Maintenance Dose (1 Month)\rInstructions:\rStep 1: INJECT 2.4mg (0.5mls OR 50u on syringe) SQ ONCE WEEKLY THEREAFTER.";
var ex_val = event.changeEx;
var tt = aInst[ex_val];
getField("TT").value = tt;
}
})();

 

The text box keeps coming up as undefined. Any help would be greatly appreciated, I have the distinct feeling it is something simple this non coder is missing. I am not getting errors in the script editor, but it is not operating as I am hoping. 

TOPICS
Create PDFs , Edit and convert PDFs , JavaScript , PDF , PDF forms
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Beginner ,
Jun 06, 2023 Jun 06, 2023

Thank you for taking time to respond to me. I do have it in as a Keystroke script for my drop down box. But for some reason the text box  TT shows "undefined" regardless of what is chosen in the drop down box. I was surprised I coudn't get it to work. While not a programmer, I am fairly savvy. I managed to mangle an active directory domain controller out of an old Ubunut box this last week and play with MQTT at home with Home Assistant without issue. Which really just means I understand enough to be dangerous and follow directions. 

 

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 06, 2023 Jun 06, 2023

This code should be used as the dropdown field's custom Keystroke script. It will probably "disappear" after you add it due to a bug in Acrobat, but should still work. It does for me.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 06, 2023 Jun 06, 2023

Thank you for taking time to respond to me. I do have it in as a Keystroke script for my drop down box. But for some reason the text box  TT shows "undefined" regardless of what is chosen in the drop down box. I was surprised I coudn't get it to work. While not a programmer, I am fairly savvy. I managed to mangle an active directory domain controller out of an old Ubunut box this last week and play with MQTT at home with Home Assistant without issue. Which really just means I understand enough to be dangerous and follow directions. 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 06, 2023 Jun 06, 2023

The script should work fine as 'Custom keystroke script', the only 'undefined' is when you add choices after you added script, but even then when start to change choices it should work fine.

You can try this as 'Custom calculation script':

if(event.value == 0) 
this.getField("TT").value = "";
else if(event.value == 1)
this.getField("TT").value = "Starting Dose (Weeks 1-12) \rInstructions: \rStep 1: INJECT 0.25mg (0.05mls OR 5u on syringe) SQ ONCE A WEEK FOR 4 WEEKS. \rStep 2: INJECT 0.5mg (0.1mls OR 10u on syringe) SQ ONCE A WEEK FOR 4 WEEKS. \rStep 3: INJECT 1mg (0.2mls OR 20u on syringe) SQ ONCE A WEEK FOR 4 WEEKS.";
else if(event.value == 2)
this.getField("TT").value = "Second Dose (Weeks 13-17) \rInstructions:\rStep 1: INJECT 1.7mg (0.35mls OR 35u on syringe) SQ ONCE A WEEK FOR 4 WEEKS.\rStep 2: INJECT 2.4mg (0.5mls OR 50u on syringe) SQ ONCE WEEKLY THEREAFTER.";
else if(event.value == 3)
this.getField("TT").value = "Maintenance Dose (1 Month)\rInstructions:\rStep 1: INJECT 2.4mg (0.5mls OR 50u on syringe) SQ ONCE WEEKLY THEREAFTER.";
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 07, 2023 Jun 07, 2023

The result you're getting means no value in the data-model matched the value of the drop-down.

Are you sure you entered them correctly? Did you use export values, by any chance?

It would be easier to help you if you shared the actual file with us.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 07, 2023 Jun 07, 2023
LATEST

I did use export values. 

 

The solution of using a Custom Calculation Script worked exactly as I was trying to make the keystroke script work, so I moved on. 

 

I was unaware of including the file. Many moons ago, when I played more in this kind of thing, uploading the entire file was frowned on. 

 

Thank you for all the replies. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines