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

Automatically select a value in a field based on response in another

adobedolly
Registered: Apr 8 2011
Posts: 2

I have 10 possible wordy character responses for field2, each of which are based on the user input in field1.
 
Example: if the user enters 1 in field1, I want abc1 to populate field2, if 2 is entered in field2, abc2 populates field2, etc. I don't want the user to be able to change the two independently.
 
Is there a way to do this?

My Product Information:
Acrobat Pro 10.0, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
adobedolly wrote:
..., if 2 is entered in field2, abc2 populates field2, etc.
Do you mean if 2 is entered in field1? Do you want field2 to be editable by the user? What should happen if they enter something in field1 for which there is no corresponding text for field2?

adobedolly
Registered: Apr 8 2011
Posts: 2
Thank you George, yes, if 2 is entered in field 1, populate field 2 with a pre-determined choice. A better description might have been to think of a check-out where a customer chooses an item (field1) and that item's price would be added to the sub-total (field2). In this case, it isn't pricing so it's not absolutely necessary that the user cannot edit field2.

Field1 is validated so there wouldn't be any options without corresponding text in field2.
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
You can set up an object to associate an item name with the corresponding price. For example:

  1. var prices = {};
  2. prices["item1"] = 1.23;
  3. prices["item2"] = 4.56;
  4. prices["item3"] = 3.14;
  5. prices["item4"] = 2.72;
Then, to retrieve the price if an item, which is given by the value in field1, you'd just do something like:

  1. // Get the item name
  2. var item = getField("field1").valueAsString;
  3.  
  4. // Get the associated price
  5. var price = prices[item];