Stephen Walsh
Stephen Walsh

Reputation: 835

Oracle Apex - Select list populates text field

I'm using Oracle Apex 4.2. I have a select list and a text field. I'm trying to create a dynamic action that should be simple enough but I'm not sure how to do it. Basically depending on what value the user selects from the list of values in the select list, the text field should then be populated. So for example:

Let's say the select list gives the user the choice to select 'Animal', 'Car', 'Person'. If the user selects 'Animal' then the text field should immediately have the value 'cat'. If the user selects 'Car' then the text field should immediately have the value 'toyota'. If the user selects 'Person@ then the text field should immediately have the value 'jim' etc.

How would I make this dynamic action?

Thanks, Stephen.

Upvotes: 2

Views: 12071

Answers (1)

Ro Milton
Ro Milton

Reputation: 2536

Create a New Dynamic Action with the following properties

Main Properties

  • Event: Change
  • Selection Type: Item
  • Item(s): [Select List]
  • Condition: No Condition

True Action

  • Action: Execute PL/SQL code
  • Fire When event Result is: True
  • PL/SQL Code:

    Option 1 - use a lookup table

    select LOOKUP_VALUE
    into :P1_TEXT
    from LOOKUP_TABLE
    where original_value = :P1_SELECT_LIST;
    

    Option 2 - Use hardcoded values

    CASE upper(:P1_SELECT_LIST)
        WHEN 'ANIMAL' THEN :P1_TEXT := 'cat';
        WHEN 'CAR' THEN :P1_TEXT := 'toyota';
        WHEN 'PERSON' THEN :P1_TEXT := 'jim';
        ELSE :P1_TEXT := null;
    END CASE;
    
  • Page Items to Submit: [P1_SELECT_LIST]

  • Page Items to Return [P1_TEXT]

Upvotes: 7

Related Questions