Oracle Apex - Select list populates text field

11,026

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]
Share:
11,026
Stephen Walsh
Author by

Stephen Walsh

Updated on June 05, 2022

Comments

  • Stephen Walsh
    Stephen Walsh about 2 years

    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.

  • Tom
    Tom over 11 years
    Good answer, but when you posted this it wasn't specified that a table lookup is required. Your javascript solution therefor won't be of service and you'd need to replace it with ajax code. However, the PLSQL option is exactly what @StephenWalsh needs, except that in the PLSQL code there should be a SQL that does the actual lookup. Change that up a bit and you'll get my vote :)
  • Stephen Walsh
    Stephen Walsh over 11 years
    Thanks @RohanM I tried the PL/SQL option first and it worked perfectly, thanks guys!
  • Ro Milton
    Ro Milton over 11 years
    No worries, glad I could help.
  • Ro Milton
    Ro Milton over 11 years
    Thanks Tom, I straightened out my answer as suggested.