Example of setting page item using javascript

Does anyone have an example of setting the value of a page item (hidden) using javascript? I have seen the following in the Forum but I am having trouble implementing it. If someone could show an example of a region it is called from, and the javascript (and where it is placed), that would be great.
I have tried something similar to this without luck so far:
function setValue(){
$x('P1_FIELD').value = 'Oracle';
Thanks!
John

Hi VS,
you should really use a "Set Value" dynamic action for that, that's much more transparent than using the onclick definition in the button attributes.
Regards
Patrick
Member of the APEX development team
My Blog: http://www.inside-oracle-apex.com
APEX Plug-Ins: http://apex.oracle.com/plugins
Twitter: http://www.twitter.com/patrickwolf

Similar Messages

  • Set value of a display only item using javascript

    I was trying to find an answer in the forum but my searches gave me no results. How do
    I set a value of a display only item using javascript (ajax)?
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://htmldb.oracle.com/pls/otn/f?p=31517:1
    -------------------------------------------------------------------

    Vikas,
    Thanks for a fast responding. The type is Saves State. However, I tried to set the value
    of a display only item using:
    <script>
      function f_setDisplayOnly ()
        {$x('P80_X').parentNode.childNodes[4].nodeValue = 1;
    </script>without a result (or error). What am I doing wrong?
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://htmldb.oracle.com/pls/otn/f?p=31517:1
    -------------------------------------------------------------------

  • Setting application items through javascript

    Is there any way to modify application items using javascript? I would work with page items, but I need something that is guaranteed to be in the session state.

    Oh yes, I know that. Well here's the exact problem (I've posted threads on it from a couple different angles previously):
    - I am trying to open a popup with a report region such that I can send a query to the popup some how, without doing a page submission of the parent page.
    - The current method I am using is to send the query by URL, but I'm reaching the limit of URL length, and it's not a particularly secure solution.
    - My latest idea was to pass-by-reference (what this thread is about), but this presented a couple of problems.
    1) I could set a parent page item dynamically by JS, but the only way I know of loading the information automatically in the popup is using onLoad -- but that's too late.
    2) I could use session state, but I risk Region condition: javascript is enabled?, page session items are not set until a page is submitted, and application session items are not accessible by JS.
    I was thinking that maybe there is some way of accessing browser session state with JS, but I guess not....

  • How to validate an text field item using javascript for numbers only.

    hi,
    how to validate an text field item using javascript for numbers only.please help me on this urgent
    please mail me solun if posible on [email protected]

    Hi,
    Page HTML header
    <script>
    function onlyNum(evt) {
      // Usage: onKeyPress="return onlyNum(event)"
      evt = (evt) ? evt : window.event;
      var charCode = (evt.which) ? evt.which : evt.keyCode;
      if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        var status = 'This field accepts numbers only!';
        alert(status);
        return false;
      var status = '';
      return true;
    </script>Item HTML Form Element Attributes
    onKeyPress="return onlyNum(event)"Br,Jari

  • Access page item from Javascript

    I have searched the forum, and based on my findings this is what I've done so far:
    I have a page item where the Google Map key is stored. I want to access it from Javascript so that I can call the Google map with the key. (Note: The key can't be hardcoded as it will be pulled from DB according to the environment/url the app is running on. e.g. - dev, test, production.)
    Here's a javascript code block:
    <script>
       var google_key = $x('P1_GOOGLE_KEY').value;
       var l_url = "http://maps.google.com/maps?file=api&amp;v=2&amp;key=" +
                   google_key +
                   "&sensor=false";
    </script>I have tried, $v('P1_GOOGLE_KEY') , $x('P1_GOOGLE_KEY') , &P1_GOOGLE_KEY. and none of them work.
    How do I access a page item from Javascript?
    Thx!
    Marc

    Marc,
    I am going to take a shot in the dark, but are you referencing this item outside of a function in your head tag? So basically it tries to reference the item on load? If so this is not going to work because the item does not exist yet. If you are using jQuery change your code to look like:
    $(document).ready(function(){
       var google_key = $x('P1_GOOGLE_KEY').value;
       var l_url = "http://maps.google.com/maps?file=api&amp;v=2&amp;key=" +
                   google_key +
                   "&sensor=false";
    });This will tell the javascript to fire after everything has fully loaded. If you are not using jQuery then you can use a little javascript snippet from here to add a ready event to your page. or you can copy paste this into a script tag.
    (function () {
      var ie = !!(window.attachEvent && !window.opera);
      var wk = /webkit\/(\d+)/i.test(navigator.userAgent) && (RegExp.$1 < 525);
      var fn = [];
      var run = function () { for (var i = 0; i < fn.length; i++) fn(); };
    var d = document;
    d.ready = function (f) {
    if (!ie && !wk && d.addEventListener)
    return d.addEventListener('DOMContentLoaded', f, false);
    if (fn.push(f) > 1) return;
    if (ie)
    (function () {
    try { d.documentElement.doScroll('left'); run(); }
    catch (err) { setTimeout(arguments.callee, 0); }
    else if (wk)
    var t = setInterval(function () {
    if (/^(loaded|complete)$/.test(d.readyState))
    clearInterval(t), run();
    }, 0);
    document.ready(function (){
    var google_key = $x('P1_GOOGLE_KEY').value;
    var l_url = "http://maps.google.com/maps?file=api&amp;v=2&amp;key=" +
    google_key +
    "&sensor=false";
    Good Luck,
    Tyson Jouglet

  • How to open a pdf from pdf target with page no using javascript

    Hi
    How to open a pdf from pdf target with page no using javascript
    Thanks in Advance.

    Hello,
    <p>Web.show_document calling .htm files saved on disk.....</p>
    Francois

  • Set page item when going to single row view

    Is there a possibility to set page items when going to single row view in an interactive report?
    APEX 4.1
    Edited by: Niels Delaere on Nov 21, 2011 4:59 AM

    Thank you for your response, can you (or anyone else) give me a little more help? I can't seem to figure out how to get this working. The thing you are doing in your demo application is exactly what I want to do. Take two values of a certain row and set them in page items Where after in single row view users can see 3 additional regions with additional information based on these values.

  • How to set a page parameter using javascript ?

    Hi:
    i'd like to set page parameter with a value taken from a textbox when clicking a button using javascript code.
    i mean, i have a textbox and a button using javascript and i want to take the value from the textbox and when onClick event happens set that value to the page parameter. How can i do this????
    Thanks.
    Best regards. Urko.

    Hi,
    Can you please elaborate your requirement. May be some better ways can be suggested. Also please mention which component you are using.
    Thanks,
    Sharmila

  • Set multiple items with javascript function in chart link

    Hi Folks
    I am able to use the javascript $s function to set the value of one item from a chart link. I need to pass values to multiple items.
    Is there a way to use javascript function to pass values for multiple items on a page from a chart link
    Appreciate your responses
    Thanks
    Gopal

    Hi Arnau,
    You need to surround your JavaScript code like this (without the spaces before and after script):
    < script language="Javascript">
      window.open("<%=ABAP_VARIABLE%>").focus();
    </script >
    Regards,
    Patrick.

  • Submit page item using AJAX

    Hi All,
    Thanks for any help in advance.
    I am trying to submit an item into the session by using AJAX iin version 4.1
    I have a application process which is an on demand: run this application process when requested by a page process.
    begin
      :P4_FISCAL_YEAR2 := :AJAX_4_FISCAL_YEAR2;
    end;then in the item :P4_FISCAL_YEAR2 have the html form element attributes set to:
    (also the page item is set to None(Default) on page action when value changed.
    onchange="selectChanged6(this)"and a page process
    <script type="text/javascript">
    function selectChanged6(filter)
    var get = new htmldb_Get(null,$v('pFlowId'), 'APPLICATION_PROCESS=SET_4_FISCAL_YEAR2',0);
    get.add('AJAX_4_FISCAL_YEAR2', filter.value);
    var ret = get.get();
    </script>The item doesnt seem to be submitting into the session and I cant figure out why, Thanks

    Marie,
    I think I have acomplished what you are looking for but if your goal is quick response time then this can fluctuate since there is 1 ajax call made to set your item value and another ajax call for every chart you want to refresh.
    This solution assumes the following:
    1. all reports are in the same language and in english.
    2. all reports are flash charts.
    here is a demo: http://apex.oracle.com/pls/apex/f?p=43401:23:0
    Go into your chart template and add the class refreshable_chart
    <div class="rounded-corner-region refreshable_chart" id="#REGION_STATIC_ID#" #REGION_ATTRIBUTES#>
    ...Create the following dynamic action on your chart page:
    Name: refresh_chart
    Event: Change
    Selection Type: Item(s)
    Item(s): P4_FISCAL_YEAR2
    True actions:
    Sequence: 10
    Action: execute pl/sql code
    Code:
    NULL;
    {code}
    Page Items to Submit: P4_FISCAL_YEAR2
    Sequence: 20
    Action: Execute JavaScript code
    Affected Elements:
    -- Type: jQuery Selector
    -- jQuery Selector: .refreshable_chart
    Code:
    {code:javascript}
    this.affectedElements.each(function(){
      apex_RefreshFlashChart(&APP_PAGE_ID., this.id.substr(1), 'en');
    {code}
    Good Luck,
    Tyson Jouglet
    Edited by: Tyson Jouglet on Dec 14, 2011 10:33 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Setting Page Item from Hyperlink

    Hi,
    I am currently developing an APEX application that will show a Google map of our kiosk locations. It builds the javascript in a PL/SQL package using htp.print. For each marker it displays for the kiosk, I'm customizing the info window displayed when the marker is clicked to show the kiosk name, the address and some hyperlinks. One of these hyperlinks will go to another APEX page that displays orders for that kiosk. So, what I'm trying to accomplish is to set a page item value on the page when the hyperlink is clicked that will be used in a page query to pull the orders. I am not much of a javascript programmer, so I'm having some issues. Here is what i'm currently attempting:
    Withiin the FOR loop that builds my markers, I have defined a 'function' as follows:
    htp.print('function setKioskCode (P4_KIOSK_CODE) {');
    htp.print('var kioskcode = '||''''||<location from cursor loop>||''''||';');
    htp.print('$x('||''''||'P4_KIOSK_CODE'||''''||').value = kioskcode;');
    htp.print('}');Then, this is how I'm building the hyperlink in the info window (i've removed the link tags and single quotes so I could post the code). Using this method, I get an error on the load of the map page that says ' Expected ")" '. I can't find any syntax errors in what i have done from what I can tell (I could definitely be wrong!).
    l_order_link := href="f?p='||v('APP_ID')||':6:'||v('SESSION')||'" onclick="javascript:setKioskCode('||''''||'P4_KIOSK_CODE'||''''||');">OrdersWhen I remove the parameter value from the javascript call like this. It loads the map successfully, but, of course, the hyperlink on the marker info window doesn't work.
    l_order_link := href="f?p='||v('APP_ID')||':6:'||v('SESSION')||'" onclick="javascript:setKioskCode();">OrdersAny help would be much appreciated. And please let me know if you need any further info.
    Thanks,
    Troy
    Edited by: tfitz on Oct 21, 2010 1:53 PM

    Thanks for the reply, Jari.
    I have determined you definitely have to use the v('APP_ID') and v('SESSION') in the href statement. Otherwise, it puts the &APP_ID. and &APP_SESSION. in the URL.
    I tried the 'onclick' syntax you provided and it still does not work. I get the error I reported above. It's looking for the closing parenthesis and doesn't like a parameter being provided. If i remove the parameter from the function, the page loads and the hyperlink goes to the proper page but it doesn't populate the page item. I don't know why it doesn't like a parameter for the function.
    Thanks, Troy.

  • HTML DB Items Using JavaScript

    I have a page that is based on a SQL Query (PL/SQL Function Body Returning SQL Query). If I call another page from one of the items using a URL such as
    f?p=&APP_ID.:6:#APP_SESSION#::::P6_ID:#ID#
    it calls the new page fine.
    If I try and call it using the example in :
    http://www.oracle.com/technology/products/database/htmldb/howtos/how_to_create_custom_popups.html
    So change it to have an HTML expression of :
    &lt;a href="javascript:callMyPopup('ID');"&gt;Notes&lt;/a&gt;
    the ID never seems to be seen.
    If i do an function callMyPopup (formItem1) {
    var formVal1 = document.getElementById(formItem1).value;
    alert('value is ' || formVal1);
    the values is also not displayed.
    This is the first time I have tried to use Javascript, is my problem because the ID is part of the Query rather than a static field ?
    Thanks
    Paul

    Hello Paul,
    Your JavaScript function will not work properly because you try to pass a form item value to that function. But you are calling the function from a query.
    Try the following:
    First, change the URL from:
    f?p=&APP_ID.:6:#APP_SESSION#::::P6_ID:#ID#
    to:
    javascript:callMyPopup('#ID#');
    Second, change the link text from:
    <img src="#IMAGE_PREFIX#...>
    to:
    Note
    Third, change your JavaScript function:
    function callMyPopup (qvalue) {
    alert('value is ' + qvalue);
    Regards,
    Tom

  • Set hidden item in Javascript

    Hi,
    I am having a hidden page item P4_SELECT in my page. I am trying to set this page item with a value in javascript function.
    function getTheCurrentRow(triggerItem){  
        alert( triggerItem.slice(6));
       document.getelementbyid(P4_SELECT).value=triggerItem.slice(6);   
    // $x(P4_SELECT).value=triggerItem.slice(6);
    </script>Eventhough i am getting value in the alert getting javascript error "P4_SELECT Undefined" .
    When i checked the "view Source" of the page it is having this line in it
    <input type="hidden" name="p_t04" value="" id="P4_SELECT"  />I tried
    $x(P4_SELECT).value=triggerItem.slice(6);But getting same result only. Can't we set hidden item values in Javascript.
    Regards,
    Jyothi

    Hi,
    If you are on Apex 3.x or higher , try
    function getTheCurrentRow(triggerItem){  
    alert( triggerItem.slice(6));
    $s("P4_SELECT", triggerItem.slice(6));   
    /* Alert hidden item value you did set */
    alert($v("P4_SELECT"));
    </script>Here is link to Apex JavaScript API document where you can find functions $s and $v I did use
    http://download.oracle.com/docs/cd/E14373_01/apirefs.32/e13369/javascript_api.htm#CDEEIGFH
    Regards,
    Jari

  • Set page item from a stored procedure

    Dear reader
    We would like to have a stored procedure to run every 10 minutes. When the procedure starts, the user has to be warned that the update process is running.
    When the procedure is finished, the user should receive a message that the update process is finished.
    What I had in mind was to set a Page 0 item 'P0_REFRESH' and set his value depending on the status of the update. Then add a dynamic action with a change event. So everytime the value of this page item changes, the user will receive a correct message.
    Does anyone know if it is possible to set a page item from a stored procedure?
    Kind regards
    Xnni

    AndyPol
    I found a solution by querying the user_jobs table. In Apex, I created two page 0 items that hold the current status of the job (online, offline) and the old value of the job.
    Online of offline in the current status item is determined by a decode on "this_sec".
    The enext step was to include a html region in P0 that contains some javascript. This javascript will display a message when the values of the new status is different from the old status ;)
    Many thanks for bringing up the ideas.
    Greetz
    Xnni

  • Conditionally set page item based on value of another item

    Hello,
    I have a form that is used to create/apply changes to records. There is an application item (APP_ITEM_PROFILE)
    that is set on login which contains a value for the user's Profile ID. This Profile ID is used through out the
    application for authorizations (conditionally present tabs, etc).
    I've set a page item on the form equal to APP_ITEM_PROFILE so that the record is stamped
    with that user's profile ID when they create a record. Users with different Profile IDs may later make changes to
    the record but I want to keep the original Profile_ID on the record.
    I am trying to populate the Profile ID conditionally in the form based on the existence of a
    record ID. If there is no ID (a new record is being entered), then I want the
    Profile ID to be that of the current user (APP_ITEM_PROFILE). If there is an ID (modification is
    being made to an existing record), then I want the keep the Profile ID that was originally saved
    with the record in MyTable.
    I have this as the source for :P11_PROFILE_ID. The type is PL/SQL Expression or Function, Always, replacing... but it
    is not working (page not found when page is run):
    begin
    if :P11_ID is not null
    then
    select PROFILE_ID
    into :P11_PROFILE_ID
    from MyTable
    where ID = :P11_ID;
    elsif :P11_ID is null
    then select nv(':APP_ITEM_PROFILE') into :P11_PROFILE_ID from dual;
    end if;
    end;
    Item Descriptions:
    ID is the record ID.
    :P11_ID is the page item of the record ID (Display as Text, saves state).
    PROFILE_ID is the user's Profile ID.
    :P11_PROFILE_ID     is the page item of the user's Profile ID.
    :APP_ITEM_PROFILE is the user's Profile ID that is set on login.
    Any help is greatly appreciated.
    Thanks,
    Matt
    Update:
    I found one of Scott's answers:
    Using IF Else to determine the value of a Item
    and modified the above code to:
    declare l_ret number;
    begin
    if :P11_ID is not null
    then
    select PROFILE_ID
    into l_ret
    from MyTable
    where ID = :P11_ID;
    else select :APP_ITEM_PROFILE' into l_ret from dual;
    end if;
    return l_ret;
    end;
    It seems to be setting the Profile ID correctly when the ID is not null, but not when a new record is being created. In the latter case, there is no value.
    Edited by: mterlesky on May 11, 2009 11:02 PM
    Edited by: mterlesky on May 11, 2009 11:52 PM
    Edited by: mterlesky on May 11, 2009 11:53 PM

    Thanks. That is putting the value into the page item and session state but that value is not being saved when the record is created. I'm not sure why - here is part of the debug (the "Billing" table is the "MyTable" table in the previous posting). Any thoughts?
    On form, before submit:
    0.06: Saving g_arg_names=P11_PROFILE_ID and g_arg_values=112
    0.06: ...Session State: Saved Item "P11_PROFILE_ID" New Value="112"
    After Submit
    0.06: ...Session State: Save "P11_PROFILE_ID" - saving same value: "112"
    (validations not shown)
    0.10: Processing point: AFTER_SUBMIT
    0.10: ...Process "Get PK": PLSQL (AFTER_SUBMIT) declare function get_pk return varchar2 is begin for c1 in (select BILLING_SEQ.nextval next_val from dual) loop return c1.next_val; end loop; end; begin :P11_ID := get_pk; end;
    0.10: ...Session State: Save Item "P11_ID" newValue="452" "escape_on_input="Y"
    0.10: ...Do not run process "Get PK for CREATEAGAIN", process point=AFTER_SUBMIT, condition type=, when button pressed=CREATEAGAIN
    0.10: ...Process "Process Row of BILLING": DML_PROCESS_ROW (AFTER_SUBMIT) #OWNER#:BILLING:P11_ID:ID|IUD
    0.10: ...Process "Update TOTAL_HOURS": PLSQL (AFTER_SUBMIT) begin Update billing set TOTAL_HOURS = ((NVL(CD_90801_UNITS,0)*1.5)+ (NVL(CD_90804_UNITS_B,0)*.5)+ NVL(CD_90806_UNITS,0)+ (NVL(CD_90808_UNITS_B,0)*1.5)+ NVL(CD_90812_UNITS,0)+ (NVL(CD_90814_UNITS_B,0)*1.5)+ NVL(CD_90846_UNITS,0)+ NVL(CD_90847_UNITS,0)+ NV
    0.11: ...Process "Update TOTAL_UNITS": PLSQL (AFTER_SUBMIT) begin Update billing set TOTAL_UNITS = (NVL(CD_90801_UNITS,0)+ NVL(CD_90804_UNITS_B,0)+ NVL(CD_90806_UNITS,0)+ NVL(CD_90808_UNITS_B,0)+ NVL(CD_90812_UNITS,0)+ NVL(CD_90814_UNITS_B,0)+ NVL(CD_90846_UNITS,0)+ NVL(CD_90847_UNITS,0)+ NVL(CD_90853_UNITS,0)+ NV
    0.11: ...Process "G_TRANS_COUNT_ADD": PLSQL (AFTER_SUBMIT) begin :G_TRANS_COUNT := :G_TRANS_COUNT +1; end;
    0.11: ...Session State: Saved Item "G_TRANS_COUNT" New Value="1"
    0.11: ...Process "Email_Notification": PLSQL (AFTER_SUBMIT) declare l_body_html varchar2(4000); begin l_body_html := '<p>Billing ID '||:P11_ID||' was entered by '||:P11_PROV_NAME||'.'|| ' More transactions may have been entered by the provider after this one.'||'</p> <p><a
    Edited by: mterlesky on May 12, 2009 9:21 AM

Maybe you are looking for