This discussion is archived
13 Replies Latest reply: Sep 27, 2012 12:05 AM by 807316 RSS

Javascript and Updateable Reports

556814 Newbie
Currently Being Moderated
I've created an updateable report using the wizard. I need to populate the last column based on the contents of 2 updateable columns.

I've searched the forum how to do this and I understand that I'll need to write some javascript to sum the values of the 2 columns and set the Element Attributes of these 2 columns so that an onchange event calls the javascript.

However, I don't know how to reference the 2 columns whose values I need, and how do I reference the column whose value I want to set.

Most of the examples I've seen use document.getElementById('P1_ITEM1').value
but since my fields are not items, but rather columns in an updateable report I can't use the element name.

Any assistance you could provide would be greatly appreciated.

Many Thanks,
Marquita
  • 1. Re: Javascript and Updateable Reports
    556814 Newbie
    Currently Being Moderated
    It's ok, I've managed to figure it out. Thanks anyway.
  • 2. Re: Javascript and Updateable Reports
    510349 Newbie
    Currently Being Moderated
    Hi,

    Is there any chance you could show how you have done this. This is a recurring issue that people (including myself) seem to come up against. Any hints/tips would be useful.

    Many Thanks,

    Cj
  • 3. Re: Javascript and Updateable Reports
    135285 Oracle ACE
    Currently Being Moderated
    Hi Chris,

    you can use the following JavaScript code to reference values of the current row in a tabular form.
    var vRow = this.id.substr(this.id.indexOf('_')+1);
    html_GetElement('f05_'+vRow).value = html_GetElement('f04_'+vRow).value+10;
    How to integrate:
    1) Go to the report column which should trigger the update event
    2) Tabular Form Element/Element Attributes:
    onchange="var vRow = this.id.substr(this.id.indexOf('_')+1); html_GetElement('f05_'+vRow).value = html_GetElement('f04_'+vRow).value+10;"
    f05 and f04 has to replaced by the field ids APEX is using to reference this tabular form column. It's similar to the Apex_Application.g_fxx arrays. The best is to view the HTML source APEX generates, or use tools like FireBug (http://www.getfirebug.com/).

    To make it more readable and to reduce transfered data I would suggest to put the code into it's own function, which you just call in the onchange. In that case follow this steps:

    1) Page HTML Header:
    <script type="text/javascript">
    function calcit(pThis)
    {
      var vRow = pThis.id.substr(pThis.id.indexOf('_')+1);
      html_GetElement('f05_'+vRow).value = html_GetElement('f04_'+vRow).value+10;
    }
    </script>
    2) Tabular Form Element/Element Attributes:
    onchange="calcit(this);"
    Hope that helps
    Patrick
    ------------------------------------------------------------------------------------
    Check out my APEX-blog: http://inside-apex.blogspot.com
  • 4. Re: Javascript and Updateable Reports
    Arie Geller Guru
    Currently Being Moderated
    Hi Patrick,

    I believe that the result of html_GetElement('f04_'+vRow).value is a string, so when you are using the '+' sign, you are actually getting the concatenation operator and not the (math) add operator.

    If you want to do some math computations you need to use JS functions like parseInt() or parseFloat() on the returned value. Using your example, it should be something like this:
    var vRow = this.id.substr(this.id.indexOf('_')+1);
    html_GetElement('f05_'+vRow).value = parseInt(html_GetElement('f04_'+vRow).value)+10;
    Regards,
    Arie.

    Message was edited by:
    ageller1
  • 5. Re: Javascript and Updateable Reports
    135285 Oracle ACE
    Currently Being Moderated
    Arie,

    you are right, the parseInt is required.
    I tested the example first by concatenating a text and changed it to a number example when posting it to the forum without retesting it.

    Thanks
    Patrick
  • 6. Re: Javascript and Updateable Reports
    442122 Newbie
    Currently Being Moderated
    Patrick,

    I created a report on dept like

    select htmldb_item.text(1,'text',10,10,'',1) field1
    , htmldb_item.text(2,'1',10,10,'onchange="calculateTotal(this);"','2') field2
    , htmldb_item.text(3,'2',10,10,'onchange="calculateTotal(this);"','3') field3
    , htmldb_item.text(4,'',10,10,'','4') field4
    from dept

    and followed your instructions on how to integrate the javascript function.

    However, it's not 'calulating' anything. In the error-console (Firefox), I get an error:

    html_GetElement("f02_" + vRow) has no properties


    Any suggestions?

    Jos
  • 7. Re: Javascript and Updateable Reports
    135285 Oracle ACE
    Currently Being Moderated
    Jos,

    can you create an example on apex.oracle.com then I can take a look.

    Patrick
    ------------------------------------------------------------------------------------
    Check out my APEX-blog: http://inside-apex.blogspot.com
  • 8. Re: Javascript and Updateable Reports
    442122 Newbie
    Currently Being Moderated
    Patrick,

    Take a look at

    http://apex.oracle.com/pls/otn/f?p=25883:13
    username : bemy
    password : guest

    Jos
  • 9. Re: Javascript and Updateable Reports
    135285 Oracle ACE
    Currently Being Moderated
    Hi Jos,

    the problem is that no unique field ids (for each cell) are generated. An item-id in HTML should always be unique, see also the comment for htmldb_item.text
    -- p_item_id = Will set the ID of the item to this value (id="...").  Must be unique!  Try concatenating some string with rownum.  Required for 508 compliance
    Your SQL statement should look like:
    select htmldb_item.text(1,'text',10,10,'','f01_#ROWNUM#') as field1
         , htmldb_item.text(2,'1',10,10,'onchange="calculateTotal(this);"','f02_#ROWNUM#') as field2
         , htmldb_item.text(3,'2',10,10,'onchange="calculateTotal(this);"','f03_#ROWNUM#') as field3
         , htmldb_item.text(4,'',10,10,'','f04_#ROWNUM#') as field4
    from dept
    I hope that will work now :-)
    Patrick
    ------------------------------------------------------------------------------------
    Check out my APEX-blog: http://inside-apex.blogspot.com
  • 10. Re: Javascript and Updateable Reports
    135285 Oracle ACE
    Currently Being Moderated
    Hi,

    just ran into same unexpected behavior of parseInt if the user enters 08 or 09 that this will not convert to 8 or 9, instead it converts to 0.

    See http://www.faqts.com/knowledge_base/view.phtml/aid/8108 for details.

    You have to use parseInt(xxx, 10) instead.

    Patrick
    ------------------------------------------------------------------------------------
    Check out my APEX-blog: http://inside-apex.blogspot.com
  • 11. Re: Javascript and Updateable Reports
    442122 Newbie
    Currently Being Moderated
    Patrick,

    It works! Thanks a lot!

    I'll watch your blog (almost) every day.

    Jos
  • 12. Re: Javascript and Updateable Reports
    697494 Newbie
    Currently Being Moderated
    hi to all,

    i have 2 reports in the same page and i need to get the column values using javascript.

    Unfortunately, Apex gives the f01_#### name for both the reports 1st updateable columns.
    So when i try to get the value from the second's report 1st column, it gives me the value of the first's report 1st column
    How can i have a unique name for every column of every report i use?

    Please help

    Reards
    Alexandros
  • 13. Re: Javascript and Updateable Reports
    807316 Newbie
    Currently Being Moderated
    Hi Jos,

    I would like to know the code that you have used for "Editor" tab. How are you able to show HTML Data(bullets, bold etc) in Tekst column in the Display report?

    Can you please help me on the same.

    Regards,
    Monika