Home » OrclApex » Oracle Apex: Get Display Value from Select List

Oracle Apex: Get Display Value from Select List

In this tutorial, you will learn how to get display value from the Select List in Oracle Apex.

Usually, when we get the value using PL/SQL V() or binding methods (:), then we get the return value from the Select List.

But if you want to get the display value from the Select List, then you have to use the JavaScript API method displayValueFor() with apex.item namespace.

Method displayValueFor() returns the display value of the selected element on behalf of the return value.

Meaning to get the display value from the Select List, you have to pass the return value as an argument to the displayValueFor() method.

Getting Display Value from The Select List in Oracle Apex

For example, we have a Select List item P2_PRODUCT_LIST based on the following query:

Select product_name d, id r 
   from eba_cust_products
order by product_name;

In this case, the Select List P2_PRODUCT_LIST will display the product name and will return the value product id.

First, we will see how to get the returned value from the P2_PRODUCT_LIST using the JavaScript, because this is also needed to get the display value.

Get Return Value from Select List Using JavaScript

apex.item('P2_PRODUCT_LIST').getValue();

The above JavaScript code will get the return value from the Select List P2_PRODUCT_LIST.

You can get this value into a variable or can show directly using the alert message. For example:

var retValue;
retValue = apex.item('P2_PRODUCT_LIST').getValue();
apex.message.alert(retValue);

Get Display Value from Select Using JavaScript

To get the display value of the selected element from P2_PRODUCT_LIST use the following code:

var retValue, displayValue;
retValue = apex.item('P2_PRODUCT_LIST').getValue();
displayValue = apex.item('P2_PRODUCT_LIST').displayValueFor(retValue);
apex.message.alert(displayValue);

Output

Get display value for selected element from select list in Oracle Apex.

Related tutorials: