Run JavaScript function after form submission in Oracle Application Express

Looking for suggestions on how to control the order of function execution?

In my work with Oracle APEX, I've set up a button labeled "export" that captures the ROWID of selected rows in an interactive grid and passes these values to a page item. The goal is to trigger a process that requires a submit. I've also created a JavaScript function called downloadFile() which generates a file download. Now, my challenge is to ensure that the downloadFile() function only runs after the submit. However, I want to keep just one button to handle passing values to page items, submitting the page, and then running the downloadFile() function.

I've attempted declaring the function globally within the page, in the JavaScript section (Function and Global Variable Declaration), and calling the function after the submit in the button. Yet, this resulted in a blank file because everything executed simultaneously, and the values were set in the page item after file generation. I also tried adding the submit action to the click event of the APEX$ROW_SELECTOR column, but it only worked for one row at a time since the selection was cleared after each submit.

I did find a workaround using two buttons. Clicking the first button captured the ROWID of selected rows, applied the submit, and clicking the second button triggered the downloadFile() function to generate the file. However, I prefer not to have two buttons for this process.

How can I ensure that the downloadFile() function runs only after the submit while keeping just one button to handle all these actions?

Answer №1

Your proposed idea may not be feasible due to the specific lifecycle phases of a page in APEX. There are three distinct phases that occur in a specific order:

  • Phase 1: Show Page - During this phase, rendering is performed using metadata stored in the database. All pre-render page processes, computations, and branches are executed, resulting in the DOM being rendered and the page ready for use.
  • Phase 2: Page Rendered - The DOM is fully rendered and available for user interaction. Client-side JavaScript can only be executed during this phase.
  • Phase 3: Accept Page - This phase occurs after the page is submitted, where any after-submit processes such as validations, computations, and processing take place.

It's important to note that these phases always occur sequentially and cannot overlap. Once Phase 3 begins, server operations take precedence, and the DOM becomes inaccessible.

If your solution involves executing JavaScript after something happens in Phase 3, it may not be viable. One possible workaround is setting a page item or request value upon submission and triggering the JavaScript function on page load under specific conditions. This can be achieved through a dynamic action on page initialization with a server-side condition.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Retrieve the image by its unique identifier while viewing a preview of the image before it is uploaded

Below is the script I am using to preview an image before it is uploaded. The HTML structure looks like this: <div> <img id="image" src="#"> </div> <input type="file" accept="image/gif, image/jpeg, image/png" onchange="readURL(th ...

Revoking existing Json Web Tokens when updating user information

Once a user logs in with their username and password, they receive an access_token containing the payload that includes their uniqueTokenIdentifier. This unique identifier is stored for each user in the database. If a user changes their password due to ac ...

Looping through multiple AJAX calls

I have come across numerous questions on this topic, but I am still struggling to find a solution that will make my code function correctly. There is a specific function for calling AJAX that I am unable to modify due to security restrictions. Here is how ...

Issues with the History API in AJAX Requests

Recently, I have come across a dynamically generated PHP code: <script> parent.document.title = 'Members | UrbanRanks'; $("#cwrocket_button").click(function(){ $("#module").load("modu ...

Parsing JSON data repeatedly using JavaScript within an HTML environment

The following code I found on a popular web development website works perfectly: <!DOCTYPE html> <html> <body> <h1>Customers</h1> <div id="id01"></div> <script> var xmlhttp = new XMLHttpRequest(); var url ...

What is the best placement for JavaScript code when using styled components?

Struggling to find the right place to insert this sorting code for my employee list in a styled component. Typically, I would just add it above the return statement of a functional component. However, React seems to be rejecting this approach. import style ...

Preventing bubbling and propagation in Ember 2.x

Is there a specific method to prevent event bubbling in Ember 2.18 in this particular situation? I couldn't find a matching example in the official documentation, but I did come across two alternative solutions on other websites. Both of them seem to ...

Delete all HTML functionalities

Is there a way to strip HTML functions when using a text area so that the content shows as plain text in a new post (div)? For example, if I type "Hello", I want it to appear as "< b > Hello < b / >", showing the whole code. Here is the code ...

Recursively converting trees in JS/ES6

Currently, I am attempting to convert a tree structure provided in the following format: {"Parent": { "Child1": ["toy1"], "Child2": { "Nephew": ["toy2", "toy3"] } } } into a standardized tree form ...

What could have caused the textbox to not show up?

<html> <head> <script src="http://code.jquery.com/jquery-1.9.1.js"></script> <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script> <title>Dynamic Creation of Div Elements Using Javascript< ...

Encountering an issue in Android Studio 1.3.1 when trying to create a SQLite

I encountered an error on line 26 of MainActivity.java. A Java NULLPOINTER Exception is being displayed. Can someone please advise me on how to resolve this issue? My code is available on GitHub. https://github.com/happyshravan/SQLite Latest LogCat error: ...

JavaScript Error - Unable to access 'getChartLayoutInterface' property of undefined in Google Charts

Recently, I came across an issue where I received a console error stating: Cannot read property 'getChartLayoutInterface' of undefined After researching similar questions, it seems that the error is due to the Google Visualization API not loadi ...

Eliminating pins from Biostall Google Maps plugin in CodeIgniter

After successfully setting up the Biostall Google Maps for Codeigniter, I am now looking to remove specific markers using ajax. The JavaScript code being executed is as follows: var myLatlng = new google.maps.LatLng(53.236114, 6.496444); var markerOption ...

How to efficiently filter objects within a child array in an ng-repeat statement, utilizing track by $index to manage duplicates

I have a variable called narrow.searchedMenu that contains 3 arrays of equal length. To display them, I am using ng-repeat with track by $index due to some duplicate elements present. <ul> <li ng-repeat="item in narrow.searchedMenu.desc ...

How can I change the behavior of the Enter key in text fields to automatically submit the form, rather than requiring the user to

Utilizing material UI for my component library, I have a compact dialog with a "recover password" button placed within the form. However, upon adding this button, I noticed that pressing the "enter" key in the text fields triggers the onClick event of the ...

Using the data () method to define Chart.js annotations in Vue.js can cause them to malfunction

I've encountered an issue while incorporating chartjs-plugin-annotations into a Vue.js application We have successfully integrated ChartJS charts into our Vue applications by defining the chart's config within the data () section of the componen ...

What is the best way to modify a single item within a v-for loop in Vue.js 3?

I am attempting to achieve the following: <tr v-for="item in items" :key='item'> <td v-for="field in fields" :key='field'> {{ item[field.toLowerCase()] }} </td> </tr> It seems that ...

Disable Jquery toolstrip while the menu is open

Currently, I am utilizing the jQuery toolstrip plugin in my project. I have a requirement to disable it whenever the sidebar menu is opened. Below are the HTML codes for my menu with li tags: <div class="sidebar-wrapper" id="sidebar-wrapper"> <ul ...

Fade effect on content in Bootstrap carousel

I am currently making some updates to the website mcelroymotors.com. One issue I have encountered while working on the homepage carousel is that the caption only pops up on the first slide, and does not appear on any of the subsequent slides. I would lik ...

Observable in RxJS with a dynamic interval

Trying to figure out how to dynamically change the interval of an observable that is supposed to perform an action every X seconds has been quite challenging. It seems that Observables cannot be redefined once they are set, so simply trying to redefine the ...