{"id":108,"date":"2016-01-24T21:50:04","date_gmt":"2016-01-24T19:50:04","guid":{"rendered":"http:\/\/geekinto.com\/?p=108"},"modified":"2016-04-10T23:08:27","modified_gmt":"2016-04-10T21:08:27","slug":"oracle-apex-api-s","status":"publish","type":"post","link":"https:\/\/howoracleapex.com\/?p=108","title":{"rendered":"Oracle Apex API  &#8220;$s()&#8221;"},"content":{"rendered":"<blockquote><p>The <a title=\"Apex JavaScript API\" href=\"http:\/\/docs.oracle.com\/cd\/E37097_01\/doc\/doc.42\/e35127\/toc.htm\" target=\"_blank\">Apex JavaScript API <\/a>has some very convenient functions to access the values of page items.<\/p><\/blockquote>\n<p>For example, if you wante to access the contents of a text field with JavaScript, would would need to reference it something like this:<\/p>\n<pre>$x(\"P2_TEXT_FIELD\").value;<\/pre>\n<p>If the item you want to reference is a display only item, then the syntax changes:<\/p>\n<pre>x = $(\"#P2_DISPLAY_ONLY\").text();<\/pre>\n<p>If you need to set the values of these items, the you need to use the varying syntax as well:<\/p>\n<pre>$x(\"P2_TEXT_FIELD\").value = \"Hello World!\";<\/pre>\n<p>or<\/p>\n<pre>$(\"#P2_DISPLAY_ONLY\").text(\"Hello World!\");<\/pre>\n<p>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(\u201c&lt;item_name&gt;\u201d):<\/p>\n<pre>x = $v(\"P2_TEXT_FIELD\");\r\ny = $v(\"P2_DISPLAY_ONLY\");<\/pre>\n<p>To set the item values use:<\/p>\n<pre class=\"lang:default decode:true \">$s(\"P2_TEXT_FIELD\",\"Hello World!\");\r\n$s(\"P2_DISPLAY_ONLY\",\"Hello World!\");<\/pre>\n<p>See an example on my <a href=\"http:\/\/apex.oracle.com\/pls\/apex\/f?p=46691:ITEM_REFERENCING\" target=\"_blank\">demo page<\/a>.<\/p>\n<pre>$x(\"P2_TEXT_FIELD\").value;<\/pre>\n<p>If the item you want to reference is a display only item, then the syntax changes:<\/p>\n<pre>x = $(\"#P2_DISPLAY_ONLY\").text();<\/pre>\n<p>If you need to set the values of these items, the you need to use the varying syntax as well:<\/p>\n<pre>$x(\"P2_TEXT_FIELD\").value = \"Hello World!\";<\/pre>\n<p>or<\/p>\n<pre>$(\"#P2_DISPLAY_ONLY\").text(\"Hello World!\");<\/pre>\n<p>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(\u201c&lt;item_name&gt;\u201d):<\/p>\n<pre>x = $v(\"P2_TEXT_FIELD\");\r\ny = $v(\"P2_DISPLAY_ONLY\");<\/pre>\n<p>To set the item values use:<\/p>\n<pre>$s(\"P2_TEXT_FIELD\",\"Hello World!\");\r\n$s(\"P2_DISPLAY_ONLY\",\"Hello World!\");<\/pre>\n<p>See an example on my <a href=\"http:\/\/apex.oracle.com\/pls\/apex\/f?p=46691:ITEM_REFERENCING\" target=\"_blank\">demo page<\/a>.<\/p>\n<p>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:<\/p>\n<pre>myArr = $v2(\"P2_SHUTTLE_CONTROL\");\r\nfor (idx=0; idx&lt;myArr.length; idx++) {\r\n\u00a0 \/\/do something with myArr[idx];\r\n}<\/pre>\n<p>An example of this functionality can be seen on my <a title=\"Array Demo\" href=\"http:\/\/apex.oracle.com\/pls\/apex\/f?p=46691:ARRAY_DEMO\" target=\"_blank\">demo page<\/a>, where I also compare $v() and $v2() when used in an array.<\/p>\n<p>Original article:\u00a0 <a href=\"http:\/\/ruepprich.wordpress.com\/2013\/01\/11\/getting-and-setting-apex-page-item-values-using-v-s-v2\/\" target=\"_blank\">http:\/\/ruepprich.wordpress.com\/2013\/01\/11\/getting-and-setting-apex-page-item-values-using-v-s-v2\/<\/a><\/p>\n<p>Resource:\u00a0<a href=\"https:\/\/ruepprich.wordpress.com\/?s=%24v%28\" target=\"_blank\">Go<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,22,12],"tags":[23],"class_list":["post-108","post","type-post","status-publish","format-standard","hentry","category-apex","category-apex-api","category-jscript","tag-apex-api"],"_links":{"self":[{"href":"https:\/\/howoracleapex.com\/index.php?rest_route=\/wp\/v2\/posts\/108","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/howoracleapex.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/howoracleapex.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/howoracleapex.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/howoracleapex.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=108"}],"version-history":[{"count":3,"href":"https:\/\/howoracleapex.com\/index.php?rest_route=\/wp\/v2\/posts\/108\/revisions"}],"predecessor-version":[{"id":113,"href":"https:\/\/howoracleapex.com\/index.php?rest_route=\/wp\/v2\/posts\/108\/revisions\/113"}],"wp:attachment":[{"href":"https:\/\/howoracleapex.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=108"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/howoracleapex.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=108"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/howoracleapex.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=108"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}