Link to home
Start Free TrialLog in
Avatar of Rads R
Rads RFlag 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
ASKER CERTIFIED SOLUTION
Avatar of Geert G
Geert G
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Rads R

ASKER

Very helpful.
Avatar of Rads R

ASKER

Used drop down
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.