Skip to main content

Flip Checkbox in Oracle APEX using HTML, CSS and JS


Here i am giving an example to create flip checkbox using HTML, CSS and JavaScript in Oracle APEX.

In this example, we will create a flip checkbox using HTML and CSS and will assign a value 'Y' if the checkbox is checked and 'N' if the checkbox is unchecked to a page item using JS.

Follow below steps to achieve this,

Step 1: Create Static Region and do copy and paste below code into source section.

HTML and CSS code:

<html>
<head>
<style>
   table {
   border-collapse: separate;
   border-spacing: 0 5px;
   }
   .cmn-toggle {
   position: absolute;
   margin-left: -9999px;
   visibilityhidden;
   }
   .cmn-toggle + label {
   display: block;
   position: relative;
   cursor: pointer;
   outlinenone;
   user-selectnone;
   }
   input.cmn-toggle-yes-no + label {
   width: 200px;
   height: 40px;
   }
   input.cmn-toggle-yes-no + label:before,
   input.cmn-toggle-yes-no + label:after {
   display: block;
   position: absolute;
   top: 0;
   left0;
   bottom: 0;
   right0;
   color: #fff;
   font-size16px;
   text-align: center;
   line-height: 40px;
   border-radius:15px;
   }
   input.cmn-toggle-yes-no + label:before {
   background-color: #b8b8b8;
   content: attr(data-off);
   transition: transform 1s;
   backface-visibilityhidden;
   border-radius:15px;
   }
   input.cmn-toggle-yes-no + label:after {
   background-color: #2196F3;
   content: attr(data-on);
   transition: transform 1s;
   transform: rotateY(180deg);
   backface-visibilityhidden;
   border-radius:15px;
   }
   input.cmn-toggle-yes-no:checked + label:before {
   transform: rotateY(180deg);
   }
   input.cmn-toggle-yes-no:checked + label:after {
   transform: rotateY(0);
   }
   .cmn-toggle cmn-toggle-yes-no
   {
   border-radius :20px;
   }
</style>
</head>
<body>
<table>
   <tr>
      <td>
         <input id="cmn-toggle-optiona" class="cmn-toggle cmn-toggle-yes-no
type="checkbox" name="P4_OPTION_A" onclick="optionaFunction()">
         <label for="cmn-toggle-optiona" data-on="Option Adata-off="Option A">
</label>
      </td>
      <br/>
      <tr>
      <td>
         <input id="cmn-toggle-optionb" class="cmn-toggle cmn-toggle-yes-no
type="checkbox" name="P4_OPTION_B" onclick="optionbFunction()">
         <label for="cmn-toggle-optionb" data-on="Option B" data-off="Option B">
</label>
      </td>
      <tr/>
         <br/>
      <tr>
      <td>
         <input id="cmn-toggle-optionc" class="cmn-toggle cmn-toggle-yes-no
type="checkbox" name="P4_OPTION_C" onclick="optioncFunction()">
         <label for="cmn-toggle-optionc" data-on="Option Cdata-off="Option C">
</label>
      </td>
      <tr/>
         <br/>
      <tr>
      <td>
         <input id="cmn-toggle-optiond" class="cmn-toggle cmn-toggle-yes-no
type="checkbox" name="P4_OPTION_D" onclick="optiondFunction()">
         <label for="cmn-toggle-optiond" data-on="Option D" data-off="Option D">
</label>
      </td>   
   </tr>
</table>
</body>
</html>

Step 2: Create a hidden items as below.

Step 3: Do copy and paste below JS code into "Function and Global Variable Declaration" section as below,

JavaScript Code:

function optionaFunction() {
    var checkBox = document.getElementById("cmn-toggle-optiona");
    if (checkBox.checked == true) {
        apex.item('P4_OPTION_A').setValue('Y');
    } else {
        apex.item('P4_OPTION_A').setValue('N');
    }
}

function optionbFunction() {
    var checkBox = document.getElementById("cmn-toggle-optionb");
    if (checkBox.checked == true) {
        apex.item('P4_OPTION_B').setValue('Y');
    } else {
        apex.item('P4_OPTION_B').setValue('N');
    }
}

function optioncFunction() {
    var checkBox = document.getElementById("cmn-toggle-optionc");
    if (checkBox.checked == true) {
        apex.item('P4_OPTION_C').setValue('Y');
    } else {
        apex.item('P4_OPTION_C').setValue('N');
    }
}

function optiondFunction() {
    var checkBox = document.getElementById("cmn-toggle-optiond");
    if (checkBox.checked == true) {
        apex.item('P4_OPTION_D').setValue('Y');
    } else {
        apex.item('P4_OPTION_D').setValue('N');
    }
}

Step 4: Create Button with submit action.

Step 5: Create PL/SQL procedure to store item values into table. Call this procedure, when you click on submit button.

The demo is here

That's it. Happy APEXing!!!...

Comments

Popular posts from this blog

Friendly URL: Redirect to Different Page after Login in Oracle APEX 20.1

Oracle has updated apex.oracle.com to APEX 20.1 which includes among other features the new Friendly URL option. Here i am giving an example to redirect to different page after login in Oracle APEX 20.1 [Friendly URL Enabled] Step 1: Define home page for each user in emp master table as below Step 2: To enable Friendly URL Syntax, follow below steps, 1) On the Workspace home page, click the App Builder icon. 2) Select an application (The Application home page appears). 3) From Application home page, you can access the Definition page in TWO ways: Click the Edit Application Properties button. From Shared Components:              1) Click Shared Components .              2) Under Application Logic, click Application Definition Attributes . The Definition page appears. 4) Under Properties, configure the Friendly URL s attribute: Click Apply Changes to save your ch...

Printing Page Numbers in RTF Template [Oracle BI Publisher]

Here I am giving an example to print the page numbers dynamically in the RTF (Rich Text Format) template. Step 1:  Go to page footer and copy and paste the below script. Page |  <?fo:page-number?>  of  <?fo:page-number-citation:xdofo:lastpage-joinseq?> <fo:page-number> :   This is the object, which is used to represent the current page-number. <?fo:page-number-citation:xdofo:lastpage-joinseq?> :  This is the syntax, which is used to represent the total number of pages. Step 2:  Load the XML and preview the result. Output: That's it. References: fo:page-number Printing Page Number Code in Oracle XMLP RTF Template

Number of Tables by their Size in Oracle Database

Here I am giving an example to find out number of tables by their size (Bytes, KB, MB, GB and TB) in oracle database. Query 1: [Bytes]  Number of all tables accessible to the  current user  in Oracle database by their size grouped into  predefined intervals . SELECT  size_interval ,         count ( * )   AS  no_of_tables    FROM   ( SELECT   DATA . segment_name table_name ,                CASE                 WHEN   DATA . bytes >  1000000000                 THEN   '1b Bytes and more'                 WHEN   DATA . bytes >  1000000    ...