These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Variable list option

Duniagdra
Registered: Sep 24 2008
Posts: 140

I found a sample on this site of a parts form with reactive drop down lists that automatically display a price. I like it's capability and would like to use something a little more sophisticated.

This is the code:

// Master List of Lists
// Each entry in this object listeral is the name of an assembly,
// The associated value is the item list, where each item is a name value pair, [<Part>,<Price>] 
var oAssemblyParts = { 
                       Chasis: [ ["-","None"], ["Rear Bracket",205.95], ["Front Bracket",185.95], ["Long Support",44.95],["Front Bearing",48.95]],
                       Clutch: [ ["-","None"], ["Plate 1",15.95], ["Plate 2",22.95], ["Inside Shaft",44.95],["Outside Shaft",32.95]],
                       Brake:  [ ["-","None"], ["Master Cylindar",139.95], ["Slave Cylindar",85.95], ["Pad",15.95], ["High Presure line",22.95]],
                       Coolant:[ ["-","None"], ["Pump",35.95], ["Thermostat",19.95], ["Coolant Line",8.95],["Reservoir",17.95]]
                     };        
 
//********************************
// All of the functions below are made "Row" generic, i.e. they work no matter
// which row the field is on that calls the function.  This is done by pre-fixing
// each of the field names with the row name. The row name can then be extracted 
// from the name of the field that calls the function and used to acquire other 
// fields on the same row.
 
////////////////
// SetPartEntries()
//
// Function for setting the parts list based on the assmebly selection value
//
// This function is specifically setup to be called from the Change Event
// of the Assembly List.  It will not work from another event because the 
// "event.value" parameter is used
//
function SetPartEntries()
{
   // Only run this code on when the selection is commited.  
   if(event.willCommit)
   {
      // There are 3 rows in the order form so in order to use other fields in 
      // the same row we first have to acquire the name of the row
      // we are operating on.  This is part of the List field's name, so we 
      // just have to split it off 
      var cRowName = event.target.name.split(".").shift();
 
      // Now get the new parts list from the Master List
      // Since the selection is being committed, event.value contains the selection text
      var lst = oAssemblyParts[event.value];
      // If an entry is selected that we don't have a parts list for, then
      // the parts list is just cleared. 
      if( (lst != null) && (lst.length > 0) )
         this.getField(cRowName + ".PartSelect").setItems(lst);
      else
      {
         this.getField(cRowName + ".PartSelect").clearItems();
      }
 
      // We have a new parts lists and the first entry is 
      // is a non-selection.  so clear the price field.
      this.getField(cRowName + ".Price").value = 0;
   }
}
 
 
////////////////
// SetPriceValue()
//
// Function for setting the price value based on the Parts selection value
//
// This function is specifically setup to be called from the Change Event
// of the Parts List.  It will not work from another event because the 
// "event.willCommit" and "event.changeEx" parameters are used
//
function SetPriceValue()
{
   // Only run this code on the un-committed change.  This fields is set up 
   // for Commit on select so we know the value will be committed
   if(!event.willCommit)
   {
      var cRowName = event.target.name.split(".").shift();
 
      // If the export value is Not a Number then 
      // set the price to zero.
      var nSelExp = 0;
      if(!isNaN(event.changeEx))
        nSelExp = event.changeEx
 
      this.getField(cRowName + ".Price").value = nSelExp;
   }
}
 
 
////////////////
// DoTotalCalculation()
//
// Function for calculating the total.  While this is a simple calculation
// putting it in a document level function instead of each individual total 
// field means that it only has to be entered once and is updated in only a 
// single location (i.e., if we have to make modifications)
//
function DoTotalCalculation()
{
   var cRowName = event.target.name.split(".").shift();
   event.value = this.getField(cRowName + ".Price").value * this.getField(cRowName + ".Quantity").value;
}

My desire:

I want a single option field that will trigger other pull downs.

example: one field to choose North America or South America or Europe.

Then, I would like a pull down option to activate based on that first option above.

example: if North America was chosen, I'd like to have the option of east, west, and central to be available. if South America, Brazil, Chile, Peru.
(this could probably be simplified by using NA-East, -West, -Central, SA-Brazil, -Peru, -Chile; that's not to important. just only selection step or two.)

Now if NA-East were chosen, I need more than one value added, so NA-East would fill in the appropriate fields of its row with say, 19, NJ, 07054. Once chosen, these values would remain fixed until manually changed by a new option selection of this row.

I would then like to be able to change that first option selection to say, South America and then chose SA-Brazil in the second row and get a similar result in related fields of same row; text, zone, reference.

Also, the script above seem to be looking a some point for numbers only, I'm having text-number combos that I need to keep as text-number combos, so I would need to not worry if the value returned is a number or not.

This is sounding all complicated and problematic to me so I'm really hoping one of you out there understands what I'm getting at and can help.

While I understand the explanation given with the code in how it works, I don't know how to extend the number of values that can be put into more then one field of same row. Also, I don't know how to get this code to just initiate off one common field that is separate from the rows. My head hurts now. I hope yours doesn't. If so, sorry.

Thanks in advance,
Jim.

Thanks in advance for any help provided,
Jim
The All Time Professional Amateur Hack

My Product Information:
Acrobat Pro 8.0, Windows
maxwyss
Registered: Jul 25 2006
Posts: 255
There are two approaches to such a problem.

If all you want is find one specific item (with all its values), you might look at a popup menu approach. You would have a button which will pop up a hierarchical popum menu which returns either the index number of the item in your master table, or directly fills the fields you are interested in. If you return the index number of the item in your master table, you then use that and fill the fields. If you want to fill the fields directly, you return an array with the values to fill.

If you really want a bunch of dynamically loaded drop downs (in other word, combo boxes), your master table might become a bit more complex. Essentially you can set the return value of each combo box element to point to an array which is structured like the setItems() array for a combo box, and then fill the subsequent box accordingly.

At the very end of your chain of combo boxes, you again would point to an array containing the values to fill into your fields.

Hope this can help.

Max Wyss.
Duniagdra
Registered: Sep 24 2008
Posts: 140
maxwyss wrote:
There are two approaches to such a problem.If all you want is find one specific item (with all its values), you might look at a popup menu approach. You would have a button which will pop up a hierarchical popum menu which returns either the index number of the item in your master table, or directly fills the fields you are interested in. If you return the index number of the item in your master table, you then use that and fill the fields. If you want to fill the fields directly, you return an array with the values to fill.

If you really want a bunch of dynamically loaded drop downs (in other word, combo boxes), your master table might become a bit more complex. Essentially you can set the return value of each combo box element to point to an array which is structured like the setItems() array for a combo box, and then fill the subsequent box accordingly.

At the very end of your chain of combo boxes, you again would point to an array containing the values to fill into your fields.

Hope this can help.

Max Wyss.
I researched this popup menu thing and saw a display of it. I like the concept. what would I need to do in order for what I want to work? Everything I've found so far seems to execute other documents or hyperlinks.

Thanks in advance for any help provided,
Jim
The All Time Professional Amateur Hack

Duniagdra
Registered: Sep 24 2008
Posts: 140
I found a popup menu as follows:
var aFruits = ["Fruits","Apples",["Oranges","navel","valencia"]];var aVeggies = ["Vegetables","Beans","Corn"]; // Create an array to hold the top level menu entriesvar aTopItems = [aFruits, aVeggies]; // Place Additional entry at end of the Top Level Item Arrayvar aBerries = ["Berries","Huckle","Goose"]; aTopItems.push(aBerries);var cRtn = app.popUpMenu.apply(app, aTopItems); if(cRtn != null)this.getField("Myfld").value = cRtn;

Now, let's say I would like something like selecting navel oranges to populate three fields with the following values:
8, fresh, 7lbs.

Would I need the even.value = cRtn; ?

How would I make this work? I'll be having multiple rows and trying to use this in a manner similar to the original code I gave here for the split shift with my fields being row1.??? and row2.???. Can this work?

Thanks in advance for any help provided,
Jim
The All Time Professional Amateur Hack

maxwyss
Registered: Jul 25 2006
Posts: 255
I have one little apology to make... I mentioned the popupMenu command, but actually had the newer popupMenuEx in mind. This second command allows to return a value which is related to the displayed text, but not the text itself.

This moves the problem a little bit. You get a return value which you can evaluate way easier. If you have set up your data in a smart way, you can make the return value to be the key (such as the index of an array element) and apply it...

You will always have a return value (that's what popupMenu and popupMenuEx provide), but you will be able to "do something" with them.

Hope this can help.

Max Wyss.
Duniagdra
Registered: Sep 24 2008
Posts: 140
Duniagdra wrote:
I found a popup menu as follows:
var aFruits = ["Fruits","Apples",["Oranges","navel","valencia"]];var aVeggies = ["Vegetables","Beans","Corn"]; // Create an array to hold the top level menu entriesvar aTopItems = [aFruits, aVeggies]; // Place Additional entry at end of the Top Level Item Arrayvar aBerries = ["Berries","Huckle","Goose"]; aTopItems.push(aBerries);var cRtn = app.popUpMenu.apply(app, aTopItems); if(cRtn != null)this.getField("Myfld").value = cRtn;

Now, let's say I would like something like selecting navel oranges to populate three fields with the following values:
8, fresh, 7lbs.

Would I need the even.value = cRtn; ?

How would I make this work? I'll be having multiple rows and trying to use this in a manner similar to the original code I gave here for the split shift with my fields being row1.??? and row2.???. Can this work?
Is there someone that can in plain english and without assuming I know something about javascript please answer this questions as I asked it. I followed a recommendation of using a popup menu and found this code here. I am now looking for, AND ONLY LOOKING FOR, how I am to commit this to inputting data to fields as originally inquired in my first post. If anyone has a recommendation of using another method to accomplish this please show code that defines your suggestion instead of just a suggestion. I'm trying to come to a conclusion here and while I do appreciate any help I get, it is frustrating going from one suggestion to another suggestion without seeing an example of code.

Thanks in advance for any help provided,
Jim
The All Time Professional Amateur Hack

Dimitri
Expert
Registered: Nov 1 2005
Posts: 1389
Hi Duniagdra,

Have you looked at this article at JavaScript Corner titled "Programming List and Combo Fields in Acrobat and LC Designer"?
(http://www.acrobatusers.com/tutorials/2007/js_list_combo_livecycle/ )

It has examples showing how to populate other fields from the selection in a dropdown box. There is a downloadable PDF with code you can examine to see how it is done.

As far as supplying you with all the code exactly for your particular situation it may be that all the scripters are too busy this week to do that (it's how most of them earn a living). Answers supplied in these forums are provided as a help to the community, not paid work. You may get lucky and someone has time to provide a full solution for you here, and maybe not. But everyone here has the best intentions in trying to help you- sorry it has been a frustrating experience for you.

Hope this helps,

Dimitri
www.pdfscripting.com
Duniagdra
Registered: Sep 24 2008
Posts: 140
Dimitri wrote:
Hi Duniagdra,Have you looked at this article at JavaScript Corner titled "Programming List and Combo Fields in Acrobat and LC Designer"?
(http://www.acrobatusers.com/tutorials/2007/js_list_combo_livecycle/ )

It has examples showing how to populate other fields from the selection in a dropdown box. There is a downloadable PDF with code you can examine to see how it is done.

As far as supplying you with all the code exactly for your particular situation it may be that all the scripters are too busy this week to do that (it's how most of them earn a living). Answers supplied in these forums are provided as a help to the community, not paid work. You may get lucky and someone has time to provide a full solution for you here, and maybe not. But everyone here has the best intentions in trying to help you- sorry it has been a frustrating experience for you.

Hope this helps,

Dimitri
www.pdfscripting.com
It's obvious by this post that I'm not going to get further assistance since she didn't read what I was asking. I'll try a new thread for popup menus. Yes, to answer your question I did find that example and if you read my post from the start that is in fact the code from it. In my original post for this thread I asked how the expand it and did not ask for someone to do the entire code. Please read entire thread before making insulting comments. I know fully well the type of help that is provided here and really don't appreciate someone trying to school me on such.

Thanks anyhow for helping in this. I think going the direction of the popup may be better. However, should someone be willing to continue in assisting me with the pulldown menu as originally posted or this popup menu code I posted, please, your help is well received and very appreciated contrary to what may have been implied here.

Thanks in advance for any help provided,
Jim
The All Time Professional Amateur Hack