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

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

Oracle Application Express Views (APEX)

Application Express Views Search SELECT * FROM apex_dictionary WHERE column_id = 0; View Comment Parent View APEX_APPLICATIONS Applications defined in the current workspace or database user. APEX_WORKSPACES APEX_APPLICATION_ALL_AUTH All authorization schemes for all components by Application APEX_APPLICATIONS

Save Selected Interactive Grid Records into a Collection - Oracle APEX

Here I am giving an example to save selected interactive grid records into a oracle apex collection. Step 1: Create a new blank page. Note: Mine was page 20. You will need to update reference to " P20 " with your page number if it's different. Step 2: Create a new interactive grid report region to the page using below query. Set Static Id "EmpDetails" to the region. SELECT  *     FROM   ( SELECT  emp . empno ,                emp . ename ,                emp . JOB ,                dept . dname department ,                dept . loc  LOCATION ,                mgr . ename  manager ,                emp . hiredate ,                 nvl ( emp . sal , 0 )  salary ,                 nvl ( emp . comm , 0 )  commission            FROM  eba_demo_chart_emp emp ,                eba_demo_chart_dept dept ,                eba_demo_chart_emp mgr           WHERE  emp . deptno = dept . deptno             AND  emp . mgr      = mgr . empno  ( + )           ORDER   BY  emp . ename