Avatar of Rads R
Rads R
Flag for United States of America asked on

APEX checkbox not working as expected

Hi APEX masters,

I have a checkbox with 2 values (val1, val2) ,
1. If I don't check any , it would execute one function1
2. If I click on val1 the  function2 executes
3. If I click on val2 , the  function3 executes and all 1,2,3  steps works fine

But when I click both (val1 and val2) it should execute another function4 but it is executing function1

I am selecting the checkbox values from a table with display and return values.
And in the code I am checking with the return values of the checkbox.

What am I doing wrong here, can anyone please let me know.

Thanks,
R
Oracle Database* ApexSQL

Avatar of undefined
Last Comment
Dmitry Kurashkin

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Geert G

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Rads R

ASKER
Very helpful.
Rads R

ASKER
Used drop down
Dmitry Kurashkin

Hello Rads,

I would agree with Geert that it is easier sometimes to use a select list with 4 options if you need to run 4 functions. But if the logic of the application requires to use 2 checkboxes, you can do the following:
1. If the processing is in PL/SQL, the value of the standard APEX checkbox consist of return values delimited with ":". So, if you have return values "val1" and "val2", and user had checked both, you will have value "val1:val2". To process it:
if :P1_CHECKBOX = '' then
    procedure1(...);
elsif :P1_CHECKBOX = 'val1' then
    procedure2(...);
elsif :P1_CHECKBOX = 'val1' then
    procedure3(...);
elsif :P1_CHECKBOX = 'val1:val2' then
    procedure4(...);
end if;

Open in new window

But in the case when you have more then 2 checkboxes situation becomes more complicated. It is better to check the presence of value with instr function:

if :P1_CHECKBOX = '' then
    procedure1(...);
elsif instr(:P1_CHECKBOX, 'val1') > 0 and instr(:P1_CHECKBOX, 'val2') = 0 then
    procedure2(...);
elsif instr(:P1_CHECKBOX, 'val2') > 0 and instr(:P1_CHECKBOX, 'val1') = 0 then
    procedure3(...);
elsif instr(:P1_CHECKBOX, 'val1') > 0 and instr(:P1_CHECKBOX, 'val2') > 0 then
    procedure4(...);
end if;

Open in new window


2. The same thing is in Javascript, if you want to process on the client side, but in this case, the delimiter is the comma.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck