APEX checkbox not working as expected

Rads R
Rads R used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Oracle dba
Top Expert 2009
Commented:
it would be easier to use a dropdown to select what function needs executing
or use a button for each function

Author

Commented:
Very helpful.

Author

Commented:
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.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial