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