Sun. Oct 24th, 2021

Requirement: In this post, I will describe how we can Execute a JavaScript code on a Button click (Dynamic Action) in Oracle APEX.

Here, we will have two items with the label as First Number and Last Number

Then there is a button with the label as Check on click of which it will check if the First Number is greater than, or equal, or less than the Second Number.

A sample screen is shown below:

Solution: For solution of the above requirement follow the steps as shown below:

Step 1: Create a blank page with the Name as “Execute JavaScript Using Dynamic Action

Step 2: Create a Region with the Title as “Check Greatest Number” and Type as “Static Content

Step 3: Create the first item and set the below properties

  • Name: P8_FIRST_NUMBER
  • Type: Number
  • Label: First Number

Step 4: Create the second item and set the below properties

  • Name: P8_SECOND_NUMBER
  • Type: Number
  • Label: Second Number

Step 5: Create a button and set the below properties:

  • Button Name: P8_CHECK
  • Label: Check

Create the Dynamic Action for the above button and set the below properties

  • Name: checkGreatestNumberDA
  • Event: Click

For the True outcome of the Dynamic Action set the Action as “Execute JavaScript Code“, and write the below JavaScript code

console.log('First Number is : ' + $v('P8_FIRST_NUMBER'));
console.log('Second Number is : ' + $v('P8_SECOND_NUMBER'));
if ($v('P8_FIRST_NUMBER') === '' && $v('P8_SECOND_NUMBER') === '') {
    apex.message.alert('Please enter both the Numbers');
} else {
    if ($v('P8_FIRST_NUMBER') > $v('P8_SECOND_NUMBER')) {
        apex.message.alert('First Number is greater than Second Number');
    } else if ($v('P8_FIRST_NUMBER') === $v('P8_SECOND_NUMBER')) {
        apex.message.alert('First Number and Second Number are equal');
    } else
        apex.message.alert('Second Number is greater than First Number'); {
    }
}

Save and run the application. Thus the ran application is shown below:

Enter the First Number as 10 and the Second Number as 20 and click on the Check button, and we can see the output as shown below:

Hence, the solution to our requirement.

If you like the post please comment, share, and do join me on Facebook. Please subscribe to my YouTube Channel for video tutorials.

Thanks & Regards,
Susanto Paul

 730 total views,  1 views today

By Susanto Paul

Susanto is an Oracle ACE, a qualified MCA, MBA, and a highly-skilled Senior Oracle Specialist. He is an enthusiastic Blogger and YouTuber who helps learners to solve their complex problems more efficiently. He has 9+ years of experience in multiple technologies like AWS, Oracle ADF, Oracle APEX, Oracle JET, Oracle VBCS, Oracle IDCS, Oracle PL/SQL, Oracle Integration Cloud, Java, JDBC, Servlets, JSP, Spring, Hibernate, HTML5, CSS3, JavaScript, TypeScript, NodesJS, Angular, MySQL, Oracle WebLogic Server, JUnit, JMeter, Selenium Web Driver, etc. He is a certified: Oracle Certified Professional Java SE 6 Programmer, Oracle ADF 11g Certified Implementation Specialist, Oracle Cloud Platform Application Integration 2020 Certified Specialist, Oracle Cloud Infrastructure Foundations 2020 Certified Associate, and Oracle Cloud Infrastructure Developer 2020 Certified Associate

Leave a Reply

Your email address will not be published. Required fields are marked *

satta king chart