It is quite easy to implement AJAX in APEX (Thanks to Carl Backstrom for a clear and conscience document). Here is a sample AJAX code to show how easy it is to use AJAX in APEX application.
The aim of my code was to select PRODUCT_NAME from Select list and populate the textarea with PRODUCT_DESCRIPTION without reloading the page. Here is what I did.
1. Created a select list P1_PRODUCT_NAME and a textarea P1_PRODUCT_DESCRIPTION.
2. In the HTML Form Element Attribute of select list I entered
onchange="getDescription( this , 'P1_PRODUCT_DESCRIPTION')"
3. In the HTML Page Header I entered the javascript which will call the ondemand process.
<script type="text/javascript"> function getDescription( pThis , pDescription) { var ajaxRequest = new htmldb_Get( 'P1_PRODUCT_DESCRIPTION' , &APP_ID. , 'APPLICATION_PROCESS=getDescription' , 0); ajaxRequest.add( 'P1_PRODUCT_NAME' , pThis.value); var ajaxResult = ajaxRequest.get(); } </script>
4. Last step is to create a ondemand process. For this go to shared component -> Click on Application process and
create a new application process getDescription
declare prod_desc varchar2(2000); id number; begin id := : P1_PRODUCT_NAME; select PRODUCT_DESCRIPTION into prod_desc from DEMO_PRODUCT_INFO where PRODUCT_ID = id; htp.prn( prod_desc ); end;
Here is the example
E X A M P L E
I can’t enter your site : http://apex.oracle.com/pls/apex/f?p=12060:101:772900707162972¬ification_msg=Invalid%20Login%20Credentials/E9C33CFD87E45F7910F6C7586A388183/ (Username/Password will be false)
Can you help me ?
By: Süleyman on September 2, 2010
at 1:27 pm
Hi Suleyman,
I just now checked and it is working fine..
Password is dragon and is case sensitive..
Try the below link
http://apex.oracle.com/pls/apex/f?p=12060:1
Regards,
Shijesh
By: shijesh on September 2, 2010
at 3:47 pm
Ok I got it to work, can you do an example on multiple items based on the select list?
By: Nelz on August 21, 2012
at 5:53 pm
REALLY GREAT
This was the only page that could teach me Ajax with Apex
By: Pablo on December 1, 2013
at 9:55 pm
id := : P1_PRODUCT_NAME;
Here the colon should be NEXT to the name
id := :P1_PRODUCT_NAME;
And the script should be
function getDescription( pThis , pDescription)
{
var ajaxRequest = new htmldb_Get( ‘P1_PRODUCT_DESCRIPTION’ , &APP_ID. , ‘APPLICATION_PROCESS=getDescription’ , 0);
ajaxRequest.add( ‘P1_PRODUCT_NAME’ , $(‘#P1_PRODUCT_NAME’).children(“option”).filter(“:selected”).text());
var ajaxResult = ajaxRequest.get();
}
Works on APEX 4.2.3
By: Pablo on December 1, 2013
at 10:30 pm
Excellent explanation.
I really appreciate your effort.
By: satpa on September 4, 2015
at 3:35 pm