APEX-AT-WORK no image

Set item value with AJAX

Von Tobias Arnhold 2.17.2010
Update an APEX item dynamically with AJAX:

// 1. Item: HTML Form Element Attributes:
onChange="javascript:fnc_setValue('P1_VALUE')";

// 2. Page: HTML Header
<script language="JavaScript1.1" type="text/javascript">
function fnc_setValue(v_item)
{
var get = new htmldb_Get(null,&APP_ID.,'APPLICATION_PROCESS=v_dummy',0);
get.add(v_item,html_GetElement(v_item).value)
gReturn = get.get();
html_GetElement(v_item).value = v_item;
get = null;
}
</script>

Denes described it more detailed (plus example) in his blog:
Setting Item Session State using Ajax

Have you seen the advanced freeze panes example like you can use in Oracle Forms?
Freeze Panes in an APEX Report: Now with columns

Updated script 22.02.2010:

// 1. Item: HTML Form Element Attributes:
onChange="javascript:fnc_setValue('P1_VALUE')";

// 2. Page: HTML Header
<script type="text/javascript">
function fnc_setValue(v_item)
{ // Works with select lists, radio buttons, ...
var get = new htmldb_Get(null,&APP_ID.,'APPLICATION_PROCESS=v_dummy',0);
get.add(v_item,$v(v_item))
// For Display as Text items add:
// html_GetElement('v_item').innerHTML = $v(v_item);
gReturn = get.get();
get = null;
}
</script>

Post Tags:

3 Comments " Set item value with AJAX "

Patrick Wolf 22 February, 2010 09:32

Hi Tobias,

a few suggestions for your code example:

-) don't use the language attribute in the script tag anymore, it's deprecated
-) instead of page 0 in the htmldb_Get call you should use the current page
-) for reading a page item you can use $v
-) for setting a page item you can use $s

Regards
Patrick

Tobias Arnhold 22 February, 2010 21:40

Hi Patrick,

thanks for the hints.

Josep Coves 22 June, 2011 14:25

Hi Tobias,

How would you do it to retrieve an item session value? I was thinking to update an item value via Application Process so after the AJAX call the page value wouldn't be the same as the session value. Therefore, I $v funcition would return wrong value.

May I have to build an XML answer at the Application Process or are there any other options?

Thanks