7 Replies Latest reply: Aug 10, 2011 10:23 PM by 868368 RSS

    Assigning Value to APEX PAGE ITEM

      Hi all,

      In Javascript I have assigned value to a page item P2_NAMES
      $("#P2_NAMES").val(Names);               //(Names is a variable used int he script)                   
      console.log($("#P2_NAMES").val());      //(to print in console of firebug)
      The problem is that the console displays the correct output but to my surprise the page passed a blank value to the next page when posted.

      When I click "Session" Button(Apex Bar in the bottom of the screen) after I run the page - I do not see the values reflected in the table of apex page items. Meaning the value assignment hasn't taken place but the console shows the output.

      I also made sure that the "Source used" for the apex page item be "Always, replacing any existing value in session state".

      Masters, Help !!!
        • 1. Re: Assigning Value to APEX PAGE ITEM
          Kiran Pawar
          Hi Shiva,

          Try this:
          It is one of the functions in JavaScript APIs for apex which is used for setting value of a DOM node:


          Hope it helps!
          • 2. Re: Assigning Value to APEX PAGE ITEM
            Thank You so much. But Still Doesn't work :(

            You're right. I can use $x.Value("#name",value); .

            The Jquery $().val(); and $x.Value(,); both seem to work as I can see from the console log output - But I cant figure out why the value of the page item is not reflected in list of page item values in the session(can see on clicking session button on apex bar) . If I use the page item to pass value to next page, it sends "" (blank) only.

            I tried dynamic actions like "Set Value" before page submit. still doesn't work.
            • 3. Re: Assigning Value to APEX PAGE ITEM
              Kiran Pawar
              Hi Shiva,

              You're right. I can use $x.Value("#name",value);
              Please check the syntax of the function in the reference link given in above post.
              Also you can use:
              The following threads indicate that you to have set item value using AJAX to reflect it in session state:



              Also the following function can help:


              Hope it helps!
              • 4. Re: Assigning Value to APEX PAGE ITEM
                Hey Kiran

                Thanks for following up. Really appreciate it.

                Jquery is not the problem. Something to do with session state. Btw, P2_NAME is a hidden page item(I don't think that matters).
                I checked firebug console and the firebug HTML. It works just fine.

                1. I can see in the HTML/Source:
                <input id="P2_NAME" type="hidden" value="shiva" name="p_t01"
                2. But in the "Session" - It's blank!
                Page: 110
                Item: 2
                Name: P2_NAME
                Display: Hidden
                Item Value:
                Encrypted: No

                Source Value used : Always, replacing any existing value in session state
                Source Type used : Static Assignment (value equals Source Attribute)

                3. When I refer to this item as &P2_NAME. in my url - It sends blank too.
                • 5. Re: Assigning Value to APEX PAGE ITEM
                  Hi Shiva

                  Page Items are sent to session state on submit or if done through Ajax call only. As Kiran pointed out to some documents/threads, you need to use JavaScript or Dynamic Action to send the Item values to the session state. Only after that you will be able to see it in Session.

                  MaxApex Hosting
                  • 6. Re: Assigning Value to APEX PAGE ITEM
                    Kiran Pawar
                    Hi Shiva,

                    There is also a function in APEX_UTIL package that will help to set session state of
                    a Page Item or Application Item :


                    But you have to write a PL/SQL process to set the session state:
                    If through JavaScript you can achieve it through: AJAX.

                    If without submitting the page then: Advanced Dynamic Action of type Execute PL/SQL Code executing above code block

                    Hope it helps!
                    • 7. Re: Assigning Value to APEX PAGE ITEM
                      Hi All,

                      Hope this is useful for people with similar problem :

                      It was a very simple solution which missed my attention - To set values to application items on a
                      page (Before going to next page or refreshing same page) (without ajax),
                      we need to use a SUBMIT request (either using apex branch or using apex f?p url syntax) (you may assert any name for the request).

                      Also when passing values to next page and using that page items set value in the javascript make sure "Save session state" is unchecked if using a apex branch.

                      Thanks Kiran for your support. I learnt there are many ways to insert values to application items from your feedback.