Skip to main content
New Participant
October 25, 2018
Answered

Return a value to a text box from a popup menu

  • October 25, 2018
  • 4 replies
  • 4423 views

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!!!

This topic has been closed for replies.
Correct answer George_Johnson

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;

4 replies

New Participant
April 25, 2023

dawit

 

New Participant
April 25, 2023

dawit wowpo

rindap53846192
Participating Frequently
January 21, 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"]);

Inspiring
January 21, 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.

rindap53846192
Participating Frequently
January 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.

New Participant
May 30, 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;

}

Bernd Alheit
Community Expert
May 30, 2019

What happens when you use the code?

New Participant
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.

George_JohnsonCorrect answer
Inspiring
October 26, 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;

New Participant
October 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

try67
Community Expert
October 26, 2018

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