Search This Blog

Showing posts with label Set a value to True/false using a checkbox on a form. Show all posts
Showing posts with label Set a value to True/false using a checkbox on a form. Show all posts

Monday, June 30, 2025

How do I Set a value to True/false using a checkbox on a form

 Using checkboxes to set True or False values on forms is a common requirement in Oracle APEX applications. Checkboxes provide a simple and intuitive way for users to indicate binary choices, such as Yes/No, Active/Inactive, or Enabled/Disabled. Properly configuring a checkbox to set a corresponding Boolean value in the database ensures data integrity and smooth application functionality. This blog will explain how to configure a checkbox item on a form to store True or False values effectively, including best practices and tips for integration with your database.

In Oracle APEX, setting a value to True or False using a checkbox on a form is a straightforward yet essential task for capturing binary user input. This is typically done by linking a checkbox item on the form to a column in the database that stores Boolean values or equivalent representations such as 'Y'/'N', '1'/'0', or True/False.

To begin, create a checkbox item on your form page that corresponds to the data column where you want to store the Boolean value. Navigate to the Page Designer, and under the region where your form resides, click to add a new item. Choose the type as "Checkbox". Assign the item a meaningful name that matches the database column, for example, P1_ACTIVE for a column named ACTIVE.

Next, configure the checkbox item's settings:

  1. Value when Checked: Set this to the value that represents True in your database. This could be 'Y', '1', or TRUE depending on your schema design.

  2. Value when Unchecked: This is important because unchecked checkboxes do not submit any value by default. Set this to the corresponding False value, such as 'N', '0', or FALSE. You can do this by setting the item's "Value when Unchecked" property under the "Settings" section.

  3. Database Column Mapping: Make sure the checkbox item is mapped to the correct database column in the form's processing logic or source query.

When the form is submitted, Oracle APEX will store the checkbox value as True or False depending on whether the checkbox was checked or not. For example, if the user checks the box, the database column will be set to 'Y'. If the user leaves it unchecked, the column will be set to 'N'.

If you use a checkbox to represent Boolean columns directly (such as NUMBER(1) with values 1 or 0), set the "Value when Checked" to 1 and "Value when Unchecked" to 0. For CHAR columns, 'Y'/'N' is common.

To ensure data consistency, verify that your form’s DML process or automatic row processing correctly handles these values during inserts and updates. This ensures that the Boolean status is correctly saved in the database.

Additionally, you can use Dynamic Actions to respond to checkbox changes on the client side, such as showing or hiding other controls based on the checkbox state.

In summary, setting a checkbox to control True/False values involves creating a checkbox item, configuring its checked and unchecked values properly, and mapping it correctly to your database column. This allows seamless binary input capture and storage within Oracle APEX applications.

Example

Step 1 – Add a checkbox and a textbox to a page

Step 2 – In the checkbox, create a dynamic action

Step 3 – set the following values

A black and grey striped object

Description automatically generated with medium confidence


A black and white image with red rectangle

Description automatically generated


A screenshot of a computer

Description automatically generated


Step 4 – In the TRUE action set the following values

A black and grey striped object

Description automatically generated with medium confidence


A screenshot of a computer

Description automatically generated


A black rectangular object with a black stripe

Description automatically generated


Step 5 _ in the FALSE action set the following values



A screenshot of a computer

Description automatically generated



A black rectangular object with a black stripe

Description automatically generated


And, your all done.

A screenshot of a checkbox

Description automatically generated A screenshot of a checkbox

Description automatically generated


Setting a checkbox to represent True or False values correctly in Oracle APEX enhances the user experience and simplifies data processing on the backend. With the right setup, you can ensure that user selections translate accurately into your application logic and database records. Whether you are creating new forms or modifying existing ones, mastering this technique is essential for robust form handling and clear data representation.