This discussion is archived
12 Replies Latest reply: Nov 21, 2009 8:33 AM by Binepal RSS

Setting item value using Javascript

skahlert Newbie
Currently Being Moderated
Hello experts!

I have a problem with setting an item value using javascript.

I have a button on my page that should set my item P1_SORT to the value 'test'.

I call the function with the following statement in the URL section of my button:
javascript:f_setItem('P1_SORT');
The problem is, that the item is not set when calling the function.
Maybe you can help me to figure out why the function is faulty and how it should be like.

The code I have (in my page header) is as follows:
<script language="JavaScript" type="text/javascript">
function f_setItem (P1_SORT)
{ 
get.add(P1_SORT,('test').value)
gReturn = get.get();
get = null; 
;
}
</script>
Thanks for your help!

Sebastian
  • 1. Re: Setting item value using Javascript
    706722 Newbie
    Currently Being Moderated
    'test' it's a string? or the name of item?

    try this:
     function f_setItem (P1_SQRT)
    { 
    var pValue='test';
    $x(P1_SQRT).value = pValue;
    }
    or
     function f_setItem (P1_SQRT)
    { 
    var pValue='test';
    $x('P1_SQRT').value = pValue;
    }
    but ofcourse it's jquery

    edit: second one will work cause the name of item is P1_SQRT - the same, as variable in function definition. If U accept jquery U should combinate with this example and i think it should work fine

    edit2: U initialized var get?
  • 2. Re: Setting item value using Javascript
    skahlert Newbie
    Currently Being Moderated
    Superb!

    It works! Just on question: What does $x stand for?

    And is it also possible to set an item, let's say P6_SORT on page 6 at the same time?

    Thanks nirud! You're awesome!

    Sebastian

    Edited by: skahlert on 17.09.2009 13:35
  • 3. Re: Setting item value using Javascript
    706722 Newbie
    Currently Being Moderated
    but remember (what I wrote in edit) that second suggestion maybe will not work with other items - U should combinate with this.

    I'm not sure I understand what U are asking "stand for".

    $x is a (as I remember) typicall jquery getElementById - or sth like that


    EDIT:
    And is it also possible to set an item, let's say P6_SORT on page 6 at the same time?
    I think it should be

    Edited by: nirud on 2009-09-17 05:45
  • 4. Re: Setting item value using Javascript
    d_wilhelm Pro
    Currently Being Moderated
    Hello,

    $x is a javascript function of apex, and has nothing to do with jquery.
  • 5. Re: Setting item value using Javascript
    706722 Newbie
    Currently Being Moderated
    yes , my mistake

    here, are all javascript functions

    http://apex.oracle.com/pls/otn/f?p=38704:1:4421274522022015
  • 6. Re: Setting item value using Javascript
    skahlert Newbie
    Currently Being Moderated
    Thanks for your explanations guys!

    The link to the javascript is really interesting and was immediately bookmarked! :-)

    I still have one more problem.

    When I set my item P1_SORT, it displays the value as I want. Either BA_LANG or INT_BEDEUTUNG.
    Each page in my application features an equivalent item that is supposed to be bound with that value.
    Thus, I have a button that is branching to page 8. In the button definition I set item P8_Sort to the value of P1_SORT.
    However, the value is not forwarded. P8_SORT is always BA_LANG! When returning to page 1, P1_SORT is automatically set to BA_LANG even I set it to INT_BEDEUTUNG earlier.
    The items are of type text(saves state).

    What is going on here? I did not define a default value whatsoever...

    Do you have an idea what is causing this problem or how to overcome it?

    This is the last problem to get the function to work!

    Regards,

    Sebastian
  • 7. Re: Setting item value using Javascript
    skahlert Newbie
    Currently Being Moderated
    As I found out, the session item value on the initial page (i.e.1) doesn't change either on value change!
    Strange...
  • 8. Re: Setting item value using Javascript
    skahlert Newbie
    Currently Being Moderated
    I just marked it as not answered since the item is not yet bound correctly!
    Oleas be so kind and read my previous posts to get an idea what misery I'm trapped in!

    Thank you ^10!

    Regards,

    Sebastian

    Edited by: skahlert on 17.09.2009 18:04
  • 9. Re: Setting item value using Javascript
    438381 Guru
    Currently Being Moderated
    Hello:

    You had it almost right. You need AJAX to set session state without submitting your page. Modify your function to be
    <script language="JavaScript" type="text/javascript">
    function f_setItem (fld)
    { 
    var get = new htmldb_Get(null,$x('pFlowId').value,null,0); // initialize get 
    get.add(fld,'test')
    gReturn = get.get();
    $s(fld,'test')
    get = null; 
    ;
    }
    </script>
    The session-state value for the page item specified in the call to f_setItem will be set to 'test' when this function is invoked.


    Varad
  • 10. Re: Setting item value using Javascript
    skahlert Newbie
    Currently Being Moderated
    @ varad!

    Thanks a lot! The session state on page 1 is finally set immediately after hitting the button. I just wonder why setting item P2_SORT on page 2 doesn't work. When changing to page 2 via a button, the button is set to bind P2_SORT ti the value of P1_SORT (which is thanks to you set correctly).
    However, it doesn't work correctly. I have to switch between those pages at least two times until the session state for P2_SORT is set correctly.
    I already tried to clear the cache on page two before branching to it etc. Is it possible to set multiple items on several pages when binding P1_SORT using Javascript. Can you give me an example maybe?

    Or do you possibly know why the item-binding is not working correctly when branching to page 2?

    Thank you!

    Sebastian
  • 11. Re: Setting item value using Javascript
    706722 Newbie
    Currently Being Moderated
    I had the same problem with application_items. I could set page item in second application (on login page) only when I refreshed page.

    I have one help answer for U - maybe it helps.

    As u wrote U can set what U want on page 1 and all items from this page, are visible on page 2:

    I think they're visible :) because I'm doing somethink like that and it works:

    example:

    http://htmldb.oracle.com/pls/otn/f?p=31517:103:1059348479244357:::RP,::

    I'm using this to open one report from second - generally U're copying other page (f.e page 300 - whole or just some part) in some region in page f.e. 5. On the page 300 U can see values of items on page 5 (in the query of report on page 300 in where clause I'm using items from page 5) - so I think it can work in Your apllication


    so maybe u can set on page 1 new item f.e. P1_SORT_FOR_P2 (with the value which U wanted to set for P2_SORT) and on the page 2 in P2_SORT set that value come from P1_SORT_FOR_P2.

    I hope u understood general of my advice ;).
  • 12. Re: Setting item value using Javascript
    Binepal Journeyer
    Currently Being Moderated
    http://download.oracle.com/docs/html/E12510_01/javascript_api.htm

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points