Skip navigation
Currently Being Moderated

Pre-fill a text field based on drop down menu selection

Feb 29, 2012 8:55 AM

Tags: #adobe #field #javascript #livecycle #pdf_fillable_forms #drop_down #populate #auto_populate

Greetings everyone!

 

I've been tasked with creating a fillable form my workplace, and unfortunately, LiveCycle (honestly, coding / scripting in general) is not my strong suit.

 

This forum has been a huge asset already, with previous suggestions being of great help.  However, I think I've gotten as far as I can without asking for some assistance.

 

My form already has drop down menus that are populated dependent upon selections made from a prior drop down menu.  I'm trying to find the option to attach a file to use as an example, but until I do (or until I edit in a link) I'll try a quick description.  The form is regarding Alarm System information, and the current fields I have pertain to Manufacturers and Models of alarm systems.  A quick comparison would be cars.  Selecting "Honda" in the first drop down would populate the second drop down with "Accord, Element, etc." as individual options.

 

What I've been tasked with adding now is Emergency Authority information for each area.  This means that the first drop down would be the type of authority (Fire, Police, etc.), the second drop down would be populated by cities based on the first choice, and the third will (hopefully) be a text field pre filled with the phone number.

 

Okay, I still can't figure out how to attach or upload a file here, so I've uploaded it to dropbox:

 

http://db.tt/a7SAVEic

 

(You'll need to click the "Add" button button next to "Authority Numbers" to expand the area).

 

I had come across this (http://forums.adobe.com/message/1334821#1334821) as a potential solution, but I can't seem to figure out how to implement it correctly.

 

If anyone is able to give me some guidance, I'd really appreciate it!

 

- Dave

 
Replies
  • Currently Being Moderated
    Feb 29, 2012 9:07 AM   in reply to DJDeeJay

    Hi Dave,

     

    When dealing with dropdowns the best event to use is the preOpen event. This means that there wouldn't be any script in the first dropdown.

     

    Then in the second dropdown you would have a relative simple script that would look back at the user's selection in the first dropdown and then populate the display items in the second dropdown.

     

    See examples here:

    http://assure.ly/jcTahK

    http://assure.ly/gcXx03

    http://assure.ly/fYCuQ2

     

    When adding an item to a dropdown, you can specify both the display item (what the user's sees) and the bound value (the value of the dropdown that is associated with the user's selection).

     

    So,

     

    this.additem("Clonmel", "(052) 1234567");

     

    This would add a city "Clonmel" to the dropdown and the value of the dropdown would be "(052) 1234567", if the user selected Clonmel.

     

    The textfield can then be given the same name as the dropdown and its binding set to Global (see the object > Binding palette when the textfield is selected).

     

    Hope that helps,

     

    Niall

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 24, 2012 11:26 AM   in reply to DJDeeJay

    Is there a way to pre-select the first choice from the second drop down list, based on the first drop down list selection.  For the "Null pattern for dropdown" example, if a user select Gender  = Male, Relationship would default to Father, but the user can still use the dropdown list select Relationship equal something else like "Son" or "Uncle".

     

    Thanks,

     

    Anh

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 24, 2012 2:06 PM   in reply to anhtinker

    Hi,

     

    you can use the setItemState method to preselect a value in a dropdown list.

     

    Select the first value (its index = 0) of drop down list 2 if "Male" is selected, else the second value.

    if ($event.change eq "Male") then
              DDL2.setItemState(0, 1)
    elseif ($event.change eq "Female") then
              DDL2.setItemState(1, 1)
     
    endif
    
     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points