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

Return a value to a text box from a popup menu

New Here ,
Oct 25, 2018 Oct 25, 2018

Ok, so I am trying to create a multi level pop up menu and have the selected option appear in a text box. I can either do this by running the script directly in the text box the result should appear in or by having a small button next to the text box to launch the script.

As an example, here is the type of script I would be using to generate the menu itself:

var aFruits = ["Fruits","Apples",["Oranges","navel","valencia"]];

var aVeggies = ["Vegetables","Beans","Corn"];

var cRtn = app.popUpMenu(aFruits, aVeggies);

I know very little about javascript and so the problem I m having is getting it to return the value to the text box. When I run this script, the menu is generated but when a selection is made, it just goes away.

So the question I have is. what code do I need to add to this to get it to return the selected option to a text filed called M-MainCaseMaterial.

Thank you in advance!!!

TOPICS
PDF forms
3.9K
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
LEGEND ,
Oct 25, 2018 Oct 25, 2018

The cRtn variable will contain the item that the user selected, or null if no item was selected. If you place the script in the Mouse Up event of a button, you'd add the following line of code at the end of the script you posted:

getField("Text1").value = cRtn || "";

This will blank the text field if the user presses escape instead of selecting an item. If you don't want to change the text field value if the user presses escape, do this instead:

if (cRtn) getField("Text1").value = cRtn;

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
LEGEND ,
Oct 25, 2018 Oct 25, 2018

The cRtn variable will contain the item that the user selected, or null if no item was selected. If you place the script in the Mouse Up event of a button, you'd add the following line of code at the end of the script you posted:

getField("Text1").value = cRtn || "";

This will blank the text field if the user presses escape instead of selecting an item. If you don't want to change the text field value if the user presses escape, do this instead:

if (cRtn) getField("Text1").value = cRtn;

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
New Here ,
Oct 26, 2018 Oct 26, 2018

Thank you for your help. I was hoping this would be a relatively simple script but it isn’t working out that way.

I am trying to make a multilevel popup menu but I keep getting an error saying “Missing ] in index description” but no matter how many times I go over this, I can’t see where I am missing any brackets or commas.

var result = app.popUpMenu[“Thermofused melamine Good 2 Sided (G2S)” , “(M1 SERIES) CabParts stock melmine” , “M1A - White (default)” , “M1B - Almond” , “M1C - Gray” , “M1D - Natural maple” , "M1E - Black” , ”M1F - White veneer core”, [“Rouke melamines (M2)” , "M2A - Antique White” , "M2B - Glacier White” , "M2C - Dove Gray” , "M2D - Silver Frost” , "M2E - Charcoal” , "M2F - Norwegian Maple” , "M2G - Hardrock Maple” , "M2H - Alabama Cherry” , "M2I - Wilsonart Shaker Cherry” , "M2J - Cinnamon Myrtle” , "M2K - Cognac” , "M2L - Mahogany” , "M2M - Wild Apple” , "M2N - Chocolate Pear” , "M2O - Cordoba Pine” , "M2P - Italian Walnut” , "M2Q - Slate” , "M2R - Summit” , "M2S - Wilsonart Blond Echo” , "opt2" , "opt3",]];

getField["Text5"].value = cRtn || “";

Obviously this is just a test list and opt 2 and opt 3 (and many more for this list) will be filled in once I can figure out why this keeps throwing errors.

Any ideas?

Jeff Steele

Owner/Graphic Artist

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 ,
Oct 26, 2018 Oct 26, 2018

You can only use straight quotes in your code, not "curvy" ones.

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
New Here ,
May 29, 2019 May 29, 2019

Hi all ,

I have some similar issue but i'm intending to have a popup menu appear when user choose a dropdown in this case (Capex and CCEP)

then once the user click one of the pop up menu it will then show / hide a drop down field

i used to be able to do this in my old PDF form but for some reason now when i created a new one it doesnt seems to work can any expert here helping me out

this is some of the code that currently i'm using

else if( event.willCommit && event.value == "Capex" && ProjectNo==  "CCEP") {

var cChoices = app.popUpMenuEx

({cName: "1.Pilot", cReturn:"1"},  

{cName: "2.Program Management",cReturn:"2"},  

    {cName: "3.Statewide",cReturn:"3"},  

    {cName: "4.System",cReturn:"4"}  

)}

if (cChoices !== "null" && CChoices== "1") {

this.getField("ProjectCode1").display = display.hidden;

this.getField("glCapex1").display = display.visible;

this.getField("glOpex1").display = display.hidden;

this.getField("ccepOpex1").display = display.hidden;

this.getField("genLeg1").display = display.visible;

this.getField("Pilot1").display = display.visible;

this.getfield("SW1").display = display.hidden;

this.getfield("System1").display = display.hidden;

this.getfield("PM1").display = display.hidden;

}

else if (cChoices !== "null" && cChoices == "2") {

this.getField("ProjectCode1").display = display.hidden;

this.getField("glCapex1").display = display.visible;

this.getField("glOpex1").display = display.hidden;

this.getField("ccepOpex1").display = display.hidden;

this.getField("genLeg1").display = display.visible;

this.getField("Pilot1").display = display.hidden;

this.getfield("SW1").display = display.hidden;

this.getfield("System1").display = display.hidden;

this.getfield("PM1").display = display.visible;

}

else if (cChoices !== "null" && cChoices == "3") {

this.getField("ProjectCode1").display = display.hidden;

this.getField("glCapex1").display = display.visible;

this.getField("glOpex1").display = display.hidden;

this.getField("ccepOpex1").display = display.hidden;

this.getField("genLeg1").display = display.visible;

this.getField("Pilot1").display = display.hidden;

this.getfield("SW1").display = display.visible;

this.getfield("System1").display = display.hidden;

this.getfield("PM1").display = display.hidden;

}

else if (cChoices !== "null" && cChoices == "4") {

this.getField("ProjectCode1").display = display.hidden;

this.getField("glCapex1").display = display.visible;

this.getField("glOpex1").display = display.hidden;

this.getField("ccepOpex1").display = display.hidden;

this.getField("genLeg1").display = display.visible;

this.getField("Pilot1").display = display.hidden;

this.getfield("SW1").display = display.hidden;

this.getfield("System1").display = display.visible;

this.getfield("PM1").display = display.hidden;

}

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 ,
May 30, 2019 May 30, 2019

What happens when you use the code?

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
New Here ,
May 30, 2019 May 30, 2019

doesnt do anything

But i kinda resolve it myself after changing it into a function and use switch instead of if then i run the function in the dropdown.

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
New Here ,
Jan 20, 2021 Jan 20, 2021

Hi there,

I am having the same issue as BigBadRocks and tried the solution you suggested with no success. I keep getting "get field null" in the console. Any ideas?

Here is the script: 

var cRtn = app.popUpMenu(["AMHR",["Over",["Halter","Geldings 100","Mares 200","Stallions 300"]],["Under",["Halter","Geldings 400","Mares 500","Stallions 600"]]],["Modern",["Halter 150","Driving 152"]],["Non-Rated","Driving 700","Obstacle 299"]);

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
LEGEND ,
Jan 20, 2021 Jan 20, 2021

What is the complete and exact text of the message that's in the console? And that doesn't look like a complete script.

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
New Here ,
Jan 21, 2021 Jan 21, 2021

Here is the complete script:

var cRtn = app.popUpMenu(["AMHR",["Over",["Halter","Geldings 100","Mares 200","Stallions 300"]],["Under",["Halter","Geldings 400","Mares 500","Stallions 600"]]],["Modern",["Halter 150","Driving 152"]],["Non-Rated","Driving 700","Obstacle 299"]);

if (cRtn) this.getField("Text1").value = cRtn;

It will only let me choose Mares 200. If I try to select any of the other options I get this in the console:

TypeError: this.getField(...) is null
3:Field:Mouse Up

If I change the "Text1" to the name of the text box (CLASSRow9), nothing happens. The list just goes away.

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 ,
Jan 21, 2021 Jan 21, 2021

This code works fine, but you're not applying in it the returned value to a field.

You're missing something like this at the end:

if (cRtn) this.getField("Text1").value = cRtn;

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
New Here ,
Jan 21, 2021 Jan 21, 2021

I tried what you said and it didn't work (see response to George above). I am missing how to connect my pop up menu to the return value. When I do a if(cRtn) app.alert(cRtn).value      I get the alert box that pops up. I need that information to go to the text box though, not an alert box. Because it needs to stay on the form and not disappear.

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 ,
Jan 22, 2021 Jan 22, 2021

app.alert(cRtn).value doesn't make sense. The value property only exists for a field object.

If you use the code I provided above but just replace "Text1" with the name of the text field it should work.

If it doesn't you'll need to share the actual file with us for further help.

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
New Here ,
Jan 22, 2021 Jan 22, 2021

I tried replacing the "Text1" with the text field name and then the list just goes away. If I use the "Text1" as is, then the first thing I select goes to the text box, but I cannot change it after that (I think you'll see that when you open the file). I have an abbreviated version of the entire script in the text field CLASSRow1. I am trying to figure out how to connect the two before playing with the whole, lengthy text. You can see that script in CLASSRow2. Which works the way I wanted it to up to the point of putting the selceted class into the CLASSRow2 box (which is a button which I figure I'll have to change). Thanks for helping. Here is the link to the file: https://www.dropbox.com/s/7l9v7cf6rskfnzc/areanat21_entryhelp.pdf?dl=0

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 ,
Jan 22, 2021 Jan 22, 2021

First of all, there are multiple code errors in the file. Change the value of any field and then check the JS Console (Ctrl+J) to see them.

 

You can't use a single text field both for triggering a pop-up menu that fills it with the selected value and allow the user to manually enter a value into it. If you want the user to be able to override the selected value manually then you should use a separate button fields to display the pop-up menu and populate the field. Then the user could still enter their own text into it.

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
New Here ,
Jan 22, 2021 Jan 22, 2021

Thank you for looking at the file. I am a complete newbie to this and I have been trying to find someone to help me. I did see in the console all of the errors, but have no idea how to fix them. The long script I wrote (completely by trial and error) I did by looking at a very simplified version on a website of how to write pop up menu scipt. I got it to look like what I was wanting, but don't understand why it is. So I have no knowledge of how to fix things when they don't do what it is I want them to do. I know one of the many errors is "Not Defined", I have no idea how to define them. Any and all help is greatly appreciated.

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 ,
Jan 22, 2021 Jan 22, 2021

The "not defined" errors mean you're referring to a function or variable name that don't exist.

 

If you wish I can look into it (and fix it) for you, for a fee. You can contact me privately via [try6767 at gmail.com] to discuss it further.

 

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
New Here ,
Apr 25, 2023 Apr 25, 2023

dawit

 

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
New Here ,
Apr 25, 2023 Apr 25, 2023
LATEST

dawit wowpo

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