Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie! -Stumped on popUpMenu Code 1

Status
Not open for further replies.

gkromjr

Technical User
Dec 12, 2004
6
US
Hello,
Thanks to tgreer I found I was in the wrong forum. Thank you tgreer. I checked out the thread and it was not what I was looking for, but WOW! What I need is to be able to choose an item from the menu by clicking it and have a field populated. Staff do not know the code abbreviations for certain fields so I need a glossary. An example would be used in a file name of demo.pdf the fieldname is "race" and I need to click on a button I created, have the popup menu show and click on "White" and have the letter "W" populate the designated field and then have the curser move to the next field.
I could only figure out the popUpMenu and it is dead. Hope it can be done.
Thanks

Code:
var reply=app.popUpMenu(
"OFFICER'S RACE",
"-",
"White = W",
"Black = B",
"American Indian/Alaskan Native = I",
"Asian/Pacific Islander = A",
"Other = O",
"Unknown = U");
 
Ok, let's start with the basics. You do know how to reference and set the value of Adobe Form Fields, right?

Assume a form with a textbox, "Text1", and a Button. You've set the button's action to "Run a JavaScript". The JavaScript might look like:

Code:
var t1 = this.getField("Text1");
t1.value = "Bubba";

Can you get that working? If so, we can move on to working with other form widgets, adding menu items, etc.



Thomas D. Greer

Providing PostScript & PDF
Training, Development & Consulting


If this post was helpful, click some ads! My personal site is also advertiser-supported. Hint, hint!
 
I re-read and realized you were working with popupMenu. You posted it, but I had in my mind adding/executing application menu items.

You're almost there! Just add a little bit of JavaScript string manipulation and you've got it:

In your button's JavaScript, try this code:

Code:
var reply=app.popUpMenu(
"OFFICER'S RACE",
"-",
"White = W",
"Black = B",
"American Indian/Alaskan Native = I",
"Asian/Pacific Islander = A",
"Other = O",
"Unknown = U");

var start = reply.indexOf("=")+2;
var choice = reply.substring(start);

var t1 = this.getField("Text1");
t1.value = choice;

"indexOf" gives you a number. That number is the place, in the string, where your search, in this case "=", occurs. Start counting at "0". Add "2" to it to get to the value you want.

"substring" needs the beginning and ending numbers, and will create a new string from them. If you leave out the "ending" number, JavaScript will give you everything to the end of the string. Since your string ends with the value, that's fine.

So the string "choice" now contains the just the value portion of the string "reply".

The final two lines retrieve the field, Text1, and set it's value to "choice".





Thomas D. Greer

Providing PostScript & PDF
Training, Development & Consulting


If this post was helpful, click some ads! My personal site is also advertiser-supported. Hint, hint!
 
Tom, Thank you for replying. I understand the code you have and yes it is pretty much like a combobox. The problem is that the staff need to enter 1 or 2 letter codes for certain verbage. Some members do not know what the codes are meant for without a booklet descibing them. I am trying to get away from the book. If I use a combobox the codes are shown, not the full description. I thought this would be easier.
When I change the fieldbox to "text1" and add the code to the button I get TypeError: t1 has no properties. If you have an email I will send you the form if you can help me better that way.
Again thanks for your assistance.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top