Eslam
Eslam

Reputation: 363

How get display value of checkbox in a checkbox group?

I am using APEX 21.1. I have a checkbox group whose list of values is retrieved using a query...

select disease, id from history;

The query returns many checkboxes. I have another textarea item. I need to get the display value for any checkbox whenever it's checked and set item HISTORY to that value. How to do so?

Upvotes: 0

Views: 4025

Answers (1)

Thomas Tschernich
Thomas Tschernich

Reputation: 1282

Describing a how-to would be so much easier if you had provided some example page item names and example data. So, lets call your checkbox group P10_CHECKBOX and your textarea P10_TEXT.

Usually, your checkbox group will save the item ids as a colon seperated list, like this: 3:4:5

To display the corresponding display values, make a dynamic action on change on your item P10_CHECKBOX.

enter image description here

Then, use an action of type Execute PL/SQL Code to fetch the display values of your items. The code could look like this:

select listagg(disease,chr(10)) within group (order by disease) into :P10_TEXT
from history h
join table(apex_string.split_numbers(:P10_CHECKBOX,':')) t on (h.id = t.column_value);

apex_string.split_numbers will convert your colon list into an actual "table" with the column column_value you can use in the join clause. listagg will do the actual concatenation and will work up to a couple thousand characters. chr(10) is an ordinary line break and will have your items be shown line by line, but any other seperator will do.

Last step is to set up P10_CHECKBOX in your Items to submit and P10_TEXT in your Items to return.

enter image description here

Now, whenever you click a checkbox, the textarea will be updated immediately.

Upvotes: 2

Related Questions