Getting and setting Apex page item values using $v(), $s(), $v2()
January 11, 2013 at 2:06 pm | Posted in Oracle Application Express (Apex), Oracle Developement | 4 CommentsTags: apex, application express, javascript, oracle
The Apex JavaScript API has some very convenient functions to access the values of page items.
For example, if you wante to access the contents of a text field with JavaScript, would would need to reference it something like this:
$x("P2_TEXT_FIELD").value;
If the item you want to reference is a display only item, then the syntax changes:
x = $("#P2_DISPLAY_ONLY").text();
If you need to set the values of these items, the you need to use the varying syntax as well:
$x("P2_TEXT_FIELD").value = "Hello World!";
or
$("#P2_DISPLAY_ONLY").text("Hello World!");
Dealing with these various syntax constructs can be confusing. Fortunately the Apex JavaScript API makes this process much easier. To get page item values simply use $v(“<item_name>”):
x = $v("P2_TEXT_FIELD");
y = $v("P2_DISPLAY_ONLY");
To set the item values use:
$s("P2_TEXT_FIELD","Hello World!");
$s("P2_DISPLAY_ONLY","Hello World!");
See an example on my demo page.
The $v2() is handy if you need to access multiple items in an array. For example multiple selections from check boxes or from a shuttle control can be fetched as an array and handled that way in JavaScript:
myArr = $v2("P2_SHUTTLE_CONTROL");
for (idx=0; idx<myArr.length; idx++) {
//do something with myArr[idx];
}
An example of this functionality can be seen on my demo page, where I also compare $v() and $v2() when used in an array.
4 Comments »
RSS feed for comments on this post. TrackBack URI
Leave a Reply
Blog at WordPress.com. | Theme: Pool by Borja Fernandez.
Entries and comments feeds.


Hi Christoph,
to set Items better use $s instead of v$, must be a copy/paste typo
Cheers,
~Dietmar.
Comment by Dietmar Aust— January 12, 2013 #
Thanks for the correction, Dietmar. It helps to have another pair of eyes check your work.
Comment by Christoph Ruepprich— January 12, 2013 #
And what about the item’s attributes like display only, hidden, etc. What syntax is used in this case to set these attributes?
Comment by David— April 24, 2013 #
David,
display only items and hidden items work the same way. You can use the Firebug console to test this out.
Cheers,
Christoph
Comment by Christoph Ruepprich— April 24, 2013 #