Javascript setting value in session state

I have a javascript that figures our the interest rate for a mortgage loan based on principal balance, term and monthly payment. The script also rounds up to the nearest 8th. Here is the line code that sets the value on the APEX form:
document.getElementById('P2_NOTE_RATE_TO_PITIA_31').value = cRate.toFixed(3);
Obviously this line code doesn't set session state for the value. Users have to submit the form again to pass this new rate to other calculations on the forms.
Is there another piece of code I need to add to force value to session state? The javascript is called via the page load and it will produce the correct rate when ever values are changed to warrant a new interest rate to be calculated.
Here is the entire javascript:
function loanrate() { 
function getVal(item){
if($x(item).value != "")
return parseFloat($x(item).value);
else
return 0 ;
//Allow rates of 0 to 100%, solve to the nearest 0.001%
var a=0.00001;
var b=1;
var tol=0.00001;
var test;
var t;
var y1;
var y2;
var P = getVal('P2_NEW_BAL_CALC');
var A = getVal('P2_NEW_PI_TARGET');
var N = getVal('P2_REMAINING_TERM');
var nRate;
var cRate;
var root;
var TEMP = a;
// Allow only 100 iterations (more than enough for convergence)
for(var k = 1; k<=100; k++) {
// A*(Math.pow((1+i),N)-1)/(i*Math.pow((1+i),N)) = present worth of N payments of A (beginning
// 1 period from now)
// Finally, subtract P (the present worth, or the price).
i = a;
y1 = A *(Math.pow((1+i),N)-1)/(i*Math.pow((1+i),N))- P;
i = b;
y2 = A *(Math.pow((1+i),N)-1)/(i*Math.pow((1+i),N))- P;
test = y1*y2;
// If test>0, the function that is to be driven to zero has the same sign
// for both sides of the interval.
if (test>0) {
b = a;
a = TEMP;
a = (a+b)/2;
} else {
// If test <0, the root of the equation is between a and b.
// If the interval is small enough, return (a+b)/2 as the root.
// If not, bisect the interval: save a as TEMP, move a (new) halfway toward b.
t = (b-a)/2;
if (t<tol) {
root = (a+b)/2;
// Compute the annual compounded rate, if payments are monthly
//var annual = 100*(Math.pow((1+root),12)-1);
root = root * 100;
nRate = Math.round(1000 * root)/1000 ;
cRate = (Math.ceil((nRate * 12)/.125)*.125);
document.getElementById('P2_NOTE_RATE_TO_PITIA_31').value = cRate.toFixed(3);
//$x_Value('P4_ANNUAL_RATE',Math.round(1000*annual)/1000);
break;
} else {
TEMP = a;
a = (a+b)/2;
}

I believe the following will do what you need.
document.getElementById('P2_NOTE_RATE_TO_PITIA_31').value = cRate.toFixed(3);
var get = new htmldb_Get(null,&APP_ID.,'APPLICATION_PROCESS=dummy',0);
get.add('P2_NOTE_RATE_TO_PITIA_31',$x('P2_NOTE_RATE_TO_PITIA_31').value)
gReturn = get.get();
...

Similar Messages

  • Setting Checkbox & Radio session state (AJAX)

    These functions will set the session state of a checkbox and radio items using Ajax.
    Any feedback is welcomed!
    // AJAX Checkbox Session
    function setCheckboxSession('P1_CHECKBOX'){
         var get = new htmldb_Get(null,html_GetElement('pFlowId').value,null,0);
         get.add(pSource,html_CheckboxValue('P1_CHECKBOX'));
         gReturn = get.get('XML');
         get = null;     
    function html_CheckboxValue(pItemId){
         var boxes=html_GetCheckbox(pItemId);
         var l_val='';
         for (var j=0;j<boxes.length;j++){
              if (boxes[j].checked){
                   l_val = boxes[j].value;
                   break;
         for (var i=j+1;i<boxes.length;i++){
              if (boxes.checked){
                   l_val = l_val+':'+boxes[i].value;
         return l_val;
    function html_GetCheckbox(pItemId){
    var l_array=new Array();
    var re=new RegExp('^'+pItemId.toUpperCase()+"_[0-9]+$");
    var inputs=document.getElementsByTagName('input');
    for (var j=0,l=inputs.length;j<l;j++)
    if (inputs[j].type=="checkbox" && inputs[j].id && inputs[j].id.match(re))
    l_array[l_array.length]=inputs[j];
    return l_array;
    // AJAX Radio Session
    function setRadioSession('P1_RADIO'){
         var get = new htmldb_Get(null,html_GetElement('pFlowId').value,null,0);
         get.add(pSource,html_RadioValue('P1_RADIO'));
         gReturn = get.get('XML');
         get = null;

    check this
    Re: Modifying session state with javascript

  • Application Item values in Session State in APEX 4.2

    In 4.2, I am not able to see the session state values of my Application Items if I click "Session" at the bottom of a page. We just migrated from 4.1 and we login to a separate app than where we land upon login. I thought the "Global" scope of the Application Item would allow this to track across apps, but its not working. Is this a known issue?

    fac586 wrote:
    Johnny98 wrote:
    In 4.2, I am not able to see the session state values of my Application Items if I click "Session" at the bottom of a page. We just migrated from 4.1 and we login to a separate app than where we land upon login. I thought the "Global" scope of the Application Item would allow this to track across apps, but its not working. Is this a known issue?When you say +"Global" scope of the Application Item+ do you mean the true global scope introduced in APEX 4.2, or are you using the term colloquially, as in "not a page item"?The new global scope introduced in 4.2
    >
    Johnny98 wrote:
    I login to App 1, but land in App 2. My Application Item lives in App 2. Upon login of App 1, an authentication scheme calls a back end function that assigns variables to the Application Item in App 2. What back end function? How does this function assign values to application items in App 2?APEX_UTIL.SET_SESSION_STATE('APP_ROLE', rec.user_type);
    >
    In APEX 4.1 I can see the session state of my Application Items by clicking on the Session button. I cannot see the session state of Application Items after moving everything to APEX 4.2.Have you selected Application Items from the View select list on the session tab and clicked the Set button?Yes, thats what started this thread

  • SET PASSWORD FROM SESSION STATE

    Hi, I need to set the password from session state but I can not do this when Display As option is set to PASSWORD. In case of Text Field works ok.
    How to accomplish this?

    Acctually I need to implement the functionality of email confirmation, but I thought a simple way is to login by clicking on a link sent by email.
    Anyhow in a password field I can not set the value, even I use a hidden item.

  • Feature Request - show substitution string values in session state display

    Hi!
    I would like to request that in addition to page and application items and session state values that the value of substitution string values be shown. Another option would be to have a separate link (like session) to display them. This would allow developers to see all of the available substitution values and how they change across pages, etc.
    Thanks!
    Dave Venus

    Dave - What are some examples of values that you are not seeing in the session state report that would be useful?
    Scott

  • Javascript Set Value

    Hallo,
    i have a Script:
    if ($('table.apexir_WORKSHEET_DATA tr').size() ==2 )
    $s('P1_VARIANTE_', $v('P1_VARIANTE'))
    when the IR Report Shows one result, the value of "P1_variante_" is become the value from "P1_variante"
    Without Submit the Page the Value is not saved
    How can i Save the Value - i tested "doSubmit('REQUEST')" and it works but the IR report is
    still 1 and Submit every time!
    I want 1 Submit.
    can you help me?
    (Sry for my bad english, i hope you can understand)
    Mike

    Just to confirm what I have understood from your original question,
    <li>You want to set that Item without submitting the page everytime the IR report is refreshed ?
    For example after a new search filter, or columnfilter ?
    If so try adding the following JS code on page load
    $('#apexir_WORKSHEET_REGION').bind('apexafterrefresh',function(){
      if ($('table.apexir_WORKSHEET_DATA tr').size() ==2 )
      $s('P1_VARIANTE_', $v('P1_VARIANTE'))
    });Note that the item is set with the value everytime on IR refresh, but it gets the new value in session only after a submit
    Also if you are using "$('table.apexir_WORKSHEET_DATA tr').size()" to identify if only one record is fetch (one heading row and one data row) , it could have issues when the report uses row breaks etc(they add extra tr's under that table element )
    Edited by: vee on Jan 26, 2011 2:48 AM

  • Using HttpHeader to set value for session variables

    Hi,
    We want to set values for 2 session variables (USER and ROLEID) using HttpHeader in obiee 11g. Has anyone tried this? How can we achieve this?
    I found the below note on the forum for setting value for the USER session variable. how can we set the ROLEID session variable also? is it possible to set values for 2 variables?
    for setting the USER session variable,
    You should add this in $BI_HOME/bifoundation/web/display/authenticationschemas.xml:
    <SchemaKeyVariable source="httpHeader" nameInSource="Proxy-Remote-User" forceValue="SSO"/>
    <AuthenticationSchema name="SSO" displayName="Single Sign On" userID="IMPERSONATE" proxyUserID="NQ_SESSION.RUNAS" options="noLogoffUI noLogonUI">
    <RequestVariable source="httpHeader" type="auth" nameInSource="Proxy-Remote-User" biVariableName="IMPERSONATE" options="required"/>
    </AuthenticationSchema>
    Please suggest.
    Thanks.

    I think maybe your SnmpValue type or value is not corrent.
    1.3.6.1.4.1.7064.201.1.200.100.0 is Enum control type
    when I use
    SnmpValue val = new SnmpString("0");
    It doesn't work, but when I use
    SnmpValue val = new SnmpInt(0);
    It works. I think the JDMK should give some warning message when the type is not correct. :)
    The code is following:
    final SnmpVarBindList setList = new SnmpVarBindList(" set varbind list ");
    SnmpOid oid = new SnmpOid("1.3.6.1.4.1.7064.201.1.200.100.0");
    SnmpValue val = new SnmpInt(0);
    SnmpVarBind valueBind = new SnmpVarBind(oid, val);
    setList.addVarBind( valueBind );
    SnmpRequest setRequest = session.snmpSetRequest(null, setList);

  • Javascript: set value of hidden item

    Hi,
    I have a select list and a hidden item on my page, after select a value, I want to write this value (and a little bit more) to the hidden item.
    So I have done the following...
    applied to page html header:
    <script language="JavaScript" type="text/javascript">
    function setExpress(item_id)
    html_GetElement('P230_HIDDEN').value = 'Test ' + html_GetElement(item_id).value;
    </script>
    and in selection list I set the HTML Form Element Attributes to onChange="setExpress(this.id); .
    But nothing is written to the hidden item. When I make it a text field it works correct.
    Isn't it possible to set a value of hidden item by javascript? Is there another way to do this (without computation)?
    Thanks for help
    chrissy

    Hello chrissy,
    I don't see the connection between the item being Hidden or Text. The item id stays the same, and so the JavaScript reference to it.
    It is possible to assign values to hidden items using JavaScript, just as you did. In the following page - http://htmldb.oracle.com/pls/otn/f?p=22814:8
    -you can see a working example of your situation – select list populate a hidden item, then display by using alert.
    After selecting from the list you should TAB out, so it will fire the JavaScript event. In your example, you were using onChange. I think that could be problematic in cases were the default value (first value) of the select list is the one chosen – no change there. In my example, I'm using onBlur.
    You can see the JavaScript on the source page.
    Hope this help,
    Arie.

  • Can I use my javascript to change the session state of an item?

    All,
    I currently have a page that has two regions: a report and a checkbox region. The checkbox region is full of checkboxes that are tied to each column in the report. I have javascript in the page HTML header that hides/displays the report column when they click the corresponding checkbox. The hiding and displaying columns works just fine.
    Here is my problem: my users need to export the report (with some columns hidden) as a CSV file. Unfortunately, the javascript function I use to hide/show the columns does not change the session value of the checkbox region and thus, APEX does not 'know' that some columns have been hidden. Because of this, APEX exports ALL columns.
    Can I add an onChange to my javascript that each time the user checks/unchecks a box, it adds/removes that item from the checkbox region's session value?
    Thanks!
    BoilerUP
    P.S. I do not want to submit the page - I would like for this to be done on the fly, just like the columns hiding/appearing with the javascript. Thanks!
    Message was edited by:
    BoilerUP

    Ok, I still cannot get this to work. I keep getting a javascript page error (yellow exclamation icon in I.E.) I have the following code in the HTML header:
    <script language="JavaScript" type="text/javascript">
    function va_GetCheckboxes(pName)
    var d=document;
    var l_return = "";
    var inputs=d.body.getElementsByTagName('INPUT');
    var l_el;
    for (var j=0;j<inputs.length;j++) {
         l_el = inputs[j];
         if (l_el.type=="checkbox" && l_el.name && l_el.name==pName
             && l_el.checked) {
                l_return += ":" + l_el.value;
    return l_return.substring(1);
    </script>I also have the following code in the HTML Form Element Attributes section for the checkbox item:
    onclick="html_HideBasedOnCheckBox(this,this.value);set_Some_Item('P2_COLUMN_HIDE_CHECKBOXES',that_string)"Do I need to replace "that_string" with something or is there something else that I'm doing wrong?

  • Use session state values to set column value during insert/update

    I am building an APEX 4.2 application that uses the canned Data Loading control to upload csv data to a table.  I have modified the 'Select Data Source' page of the workflow and it now contains three LOV's that the user selects values from.  The selected values are stored in Session State.  As I'm new to APEX, I do not know how to reference Session State objects in the context of the Data Loading workflow so that the appropriate columns are set with the correct values.  My assumption is that the columns that are apart of the insert statement reside in a collection somewhere.  I just don't know how to loop through the collection, determine the correct column, and then set that column's value equal to the corresponding LOV value in Session State.

    Scott,
    This is in version 2.2.1 and there are no caching features available.
    The application does require login.
    I'm playing around with the APP_UNIQUE_PAGE_ID right now but I am finding that even in the builder if I edit the attributes of a report column and then try to edit another column it will bring up the last column I edited. Even if I use the record navigation buttons next to the Apply Changes button it will keep bringing me the same page over and over unless I constantly refresh the pages.
    Greg

  • Trouble setting the session state of a select item.

    Hi,
    I have a requirement whereby I need to change the session state of a select list item in my form without the need to submit. I am using Application Express 4.1.0.00.32. I thought this would be straight forward using a dynamic action or javascript and calling an on demand process for example.
    P1_MY_SELECT onchange="set_option();"
    function set_option() {
    var l_option=$f_SelectValue('P1_MY_SELECT');
    alert( 'My new value is ' + l_option );
    // ON DEMAND Set the new session state value
    var lRequest = new apex.ajax.ondemand
    ('SET_P1_MY_SELECT',function()
    {  /* start the return function */
    var l_s = p.readyState;
    if(l_s == 1||l_s == 2||l_s == 3)
    else if(l_s == 4)
    { gReturn = p.responseText;
         (gReturn)?json_SetItems(gReturn):null;
    else{return false;}
    /* end the return function */
    lRequest.ajax.addParam('x01', l_option );
    lRequest._get()
    My on demand application process
    DECLARE
    l_options varchar2(2000) := wwv_flow.g_x01;
    BEGIN
    APEX_UTIL.SET_SESSION_STATE('P1_MY_SELECT',l_options);
    apex_util.json_from_items('P1_MY_SELECT');
    END;
    Is there a better method to set the session state of my P1_MY_SELECT other than what I am doing as above or can you tell me why the session state of P1_MY_SELECT is not changed?
    Thanks.
    Edited by: 968358 on 01-Nov-2012 08:40

    if you are on 4.1 why don't you use a dynamic action instead of writing the code again?
    create a dynamic action like this
    Event: Change
    Source Type: Item
    Item: P1_MY_SELECT
    True Action:
    =========
    Action: Execute Plsql Code
    Plsql Code: null;
    Page Items to Submit: P1_MY_SELECT
    Page Items to Return: P1_MY_SELECT (this is optional)
    http://docs.oracle.com/cd/E23903_01/doc/doc.41/e21674/advnc_dynamic_actions.htm#HTMDB27020

  • Submitting the value of an item with session state

    Hi,
    I've a Master / Detail Form on different pages, like master report page no.19, master form page no. 20 and detail form page no. 21. I've created this form using Form, master detail form wizard. I've set deptid as a primary key in master, and foreign key in details table. In page 21, i've set the source for deptid, source used : Always, replacing any existing value in session state, source type : Item (application or page item name), source value : P20_DEPTID. While executing the form deptid is showing the value, but, while submitting of the form, it's not saving in the table. What will be the problem??
    Thanks and Regards,
    Sudha.

    Sudha,
    OK.
    Go to the pagedefintion in page 20, click on the wordt report (of your master form).
    You will get a new screen.
    Click on the pencil-icon of your column.
    Again a new screen.
    Select the six tab (it's called LINK).
    Enter item-name and value something like :p21_dept_id and #DEPT_ID#
    where P21_dept_id is the item of the form for the dept_id
    Hope this helps.
    Leo

  • Setting session state post-authentication

    Hi all,
    This application uses DATABASE ACCOUNT authentication, and has a post-authentication process that sets a few application items using code such as
    apex_util.set_session_state('F_MY_ITEM', v_my_value);These items are used to secure certain tab options within the application.
    The post-authentication PL/SQL works fine, I can't see anything wrong the the logic. I've debugged it and I know the values are being set. I'm checking the value of session state straight after using v('F_MY_ITEM'), along with checking my session ID matches up - everything seems ok there.
    The issue is that when I log in, the session state is not set for those items - even though the post-auth process is called with no errors raised. Apex debug states
    ... Session State: Save "MY_ITEM" - saving same value "Y"If I log out, then log in (without closing browser tab), the values are now set as expected (visual confirmation using conditionally displayed tabs, and of course checking session state from developer toolbar)
    Notably, Debug states something slightly different
    ... Session State: Save item "MY_ITEM" newValue="Y" escape_on_input="Y"There are a few other differences with the debug output, this this seems the most pertinent.
    The only difference I've been able to track down is if I'm logged into the application builder in the same browser.
    If I attempt to log in with a freshly opened browser, navigate directly to application URL, the behaviour works as expected. Tabs appear as if items are set.
    Could the fact I'm authenticated in the application builder be messing with session state behaviour?
    This is with Apex 4.0.2.00.07; agnostic to browser (IE/FF/Chrome); 11gr2
    Cheers,
    Scott

    I did consider this because I experienced the same thing with page processes.
    However, in this case my post-auth function is within a package and I don't use bind variables.
    I was essentially doing this in my package:
    apex_util.set_session_state('F_MY_ITEM', 'Y');
    my_log_proc(v('F_MY_ITEM'));And seeing Y in the debug log, yet once on my home page, viewing session state I see F_MY_ITEM as empty - unless in the scenario I described.
    It's not a showstopper since the users won't be logged in to the application builder, but it would be nice to know the cause.

  • Can't Set Session State from the Login Page

    I have a dilema. On the standard login page I enter values in 2 fields namely, CAMPUS (Select List) and USERNAME (text field).
    After clicking on the login button I want to navigate to PAGE 1 and use the values of CAMPUS and USERNAME to filter data. I have created two APPLICATION Level items (A_USERNAME,A_CAMPUS) to which I assign the values of USERNAME and CAMPUS in two AFTER SUBMIT computations on the login page.
    When I arrive on PAGE 1 the session state values of A_USERNAME,A_CAMPUS are still both null therefore the query returns null. It seems that the login process does not issue a SUBMIT for session state to be saved. How do I save the values in session state on login?
    In the Login PROCESS, can I specify the Page 1 items to be set and the values to set them in a URL somewhere? Is it here?
    wwv_flow_custom_auth_std.login(
    P_UNAME => :P101_USERNAME,
    P_PASSWORD => :P101_PASSWORD,
    P_SESSION_ID => v('APP_SESSION'),
    P_FLOW_PAGE => :APP_ID||':1' <<========here?
    If so what is the correct syntax?
    If I revisit the login page a second time, a submit is issued and the values are set in session state.
    Anyone got any ideas??
    I tried creating a standard position button which issues a submit but this didn't work either.
    regards
    Paul J Platt

    Unfortunately your solution is causing problems with retrieving cookies that I try to get for the campus and username during a "Before Header Process" as well. The cookies are normally set on an "After Submit" process. When I return to the login page I get
    Error ERR-1029 Unable to store session info. session=10760914996048113736 item=8561939526127479
    ORA-02291: integrity constraint (FLOWS_010600.WWV_FLOW_DATA_FK) violated - parent key not found
    But if I turn the cookies off, it seems to work OK.
    regards
    Paul JP

  • Session State Protectio Violoation in Apex 4.2 Page Items

    I'm testing my Apps that I upgraded from 3.2 to 4.2 and getting the message below and haven't been able to understand why.
    Error Session state protection violation: This may be caused by manual alteration of protected page item P2_PAY_NO. If you are unsure what caused this error, please contact the application administrator for assistance
    How the Page works.
    1. Before Region Process runs that pre-populates some of my Text Items.
    2. The user then has the ablibity to select from a select list item that will re-populate the items populated during the Before reqion based on the date selected.
    I do this by calling the code below with an "onchange="javascript:date_populate(this);" on the HTML Form Elements Attributes.
    {var myString = $x(pThis).value;
    var mySplitResult = myString.split("|");
    $x('P2_START_DATE').value = mySplitResult[0];
    $x('P2_PAY_YEAR').value = mySplitResult[1];
    $x('P2_PAY_NO').value = mySplitResult[2];
    $x('P2_PICT_CODE').value = mySplitResult[3];
    $x('P2_END_DATE').value = mySplitResult[4];}
    3. When I submit the page I get the Session State Violation.
    All Items have "Session State Proection" set to "Unrestricted"
    Session State Protection is "Disabled" for the application.
    Edited by: spuchc on Apr 12, 2013 2:07 PM

    Check you are not updating items of type "Display Only".
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.apress.com/9781430235125
    http://apex.oracle.com/pls/apex/f?p=31517:1
    http://www.amazon.de/Oracle-APEX-XE-Praxis/dp/3826655494
    -------------------------------------------------------------------

Maybe you are looking for