Skip to main content
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

Participant
April 25, 2023

dawit

 

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"]);

try67
Community Expert
Community Expert
January 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;

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


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.

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

What happens when you use the code?

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;

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
Community Expert
October 26, 2018

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