APEX: Save a user’s checkbox selection on local PC
You want a checkbox item on a page which is a preference, you want it to be remembered for the user across login sessions, but you don’t want the overhead of storing it in a database table. You might choose to store the value in a cookie instead. It may be lost (e.g. when the user clears their cookies or changes to a different browser or another computer), but we don’t mind – it’s just a preference.
1. Create checkbox item, e.g. P1_STAY_ON_PAGE
Display As = Checkbox
Template = No Label
List of values definition =
STATIC2:Stay on page;Y
2. Add dynamic action to the checkbox item to save it when it’s changed
Event = Change
Selection Type = Item(s)
Item(s) = P1_STAY_ON_PAGE
Condition = (none)
Fire On Page Load = (No)
3. Add dynamic action on page load to load it
Event = Page Load
Note that the cookie name (“APEX_P1_STAY_ON_PAGE” in this example) is up to you to choose. Probably best to try making it specific to your application so it doesn’t clash with anything else.
14 August 2014 - 4:04 pm
You might want to consider looking at localStorage as an alternative to Cookies. Cookies are being sent to the server with each http-request, localStorage is in the browser only.
19 August 2014 - 6:32 pm
The old “GetCookie” and “SetCookie” are functions in the legacy.js file and are tagged deprecated.