Home » Developer & Programmer » Application Express, ORDS & MOD_PLSQL » How to compute "a * b = c"? (Apex 3.2.1, Oracle 10g XE, MS Windows XP SP3, IE7)
How to compute "a * b = c"? [message #459573] Mon, 07 June 2010 03:43 Go to next message
Littlefoot
Messages: 21580
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
I have recently installed Apex 3.2.1, imported an Excel table and Wizard created a sample application which I'm now trying to "improve". Obviously, I'm not very good at it.

On the other hand, I know Oracle Forms. I'm not sure this is an advantage, because certain features are much different from what I'm accustomed to.

Most probably solution of my problem is very simple. This is what I'd like to do: compute "a * b" and put it into "c".

For an illustration, perhaps it is better to post a screenshot of what I have: this is a form (called from an interactive report), that can be used both for modifying existing records, as well as inserting new ones. This is how it looks like in "update" mode:

/forum/fa/7882/0/

As you can see, "Litara * Cijena = Iznos". No problem about it - I created a computation:
- Type = SQL Query
- Computation point = Before Region(s)
- Source (Computation) = select round(:p22_cijena * :p22_litara, 2) from dual

Now, the same form in "insert" mode (which troubles me):

/forum/fa/7883/0/

I'd like the form to "automatically" compute "10 * 5" and put the result into the "iznos" item. But, I don't know how to do that.


Reading the documentation and googling for the solution (I read quite a few OTN Apex Forum discussions), I found out (perhaps I'm wrong, I don't know) that JavaScript is what I need. Unfortunately, I know less than zero about it.

This is the OTN Apex Forum topic I found interesting, so I tried to simulate what they have done.

This is my attempt:
  • In page (it is page 22) HTML Header I wrote this "script" (most probably wrong, but I don't know better):
    <script language="JavaScript">
      function izracunaj_iznos()
        (
        $x('P22_IZNOS').value == $x('P22_LITARA').value * $x('P22_CIJENA').value
        )
    </script>

  • In P22_CIJENA's "Element" section, I put
    onblur="izracunaj_iznos()"
    into the "HTML Form Element Attributes" field.

    Why did I do that? Because I found that someone managed to - using the following script
    <script type="text/javascript">
      function test(){
        window.alert('This is a test.');
      }
    </script>
    
    along with
    onblur="test()"
    display a message on the screen.

    Yes, I know - I don't want a message. But, once again, I'm an absolute beginner in that. I checked list of HTML Events and tried a few more but - no success either.

The result (after leaving the "cijena" field is /forum/fa/7884/0/ message at the bottom of my Internet Explorer 7 window.

I also tried some more options, such as changing "Iznos" field's "Source" properties to "SQL Query", "PL/SQL function body" and similar, but - no success either.

I'm afraid I'm out of ideas.

Could someone, please, point me into the right direction? What should I read (hopefully, not the whole Java Scripting and HTML documentation).

Is there an "easy" way to do such a trivial thing as "a * b = c"?
  • Attachment: g_01.PNG
    (Size: 7.09KB, Downloaded 1120 times)
  • Attachment: g_02.PNG
    (Size: 5.87KB, Downloaded 1140 times)
  • Attachment: g_03.PNG
    (Size: 0.99KB, Downloaded 1174 times)
Re: How to compute "a * b = c"? [message #459575 is a reply to message #459573] Mon, 07 June 2010 04:00 Go to previous messageGo to next message
delna.sexy
Messages: 941
Registered: December 2008
Location: Surat, The Diamond City
Senior Member
Hi Littlefoot,

Welcome to world of ApEx.

To achieve your goal,
1>You can add one computation which will be executed on submission event. And in this way, you can show the value of item 'Iznose' to the end user. You can put one button near that item, with label 'Compute' to execute the computation you created.
2>If you don't need to show the computed value of Iznose, compute that value on clicking 'Create' button and use that value as required.
3>If you need to show computed value into Iznose without submitting the page, use java script.

regards,
Delna
Re: How to compute "a * b = c"? [message #459576 is a reply to message #459575] Mon, 07 June 2010 04:10 Go to previous messageGo to next message
Littlefoot
Messages: 21580
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
I think that the third option you mentioned is what I'm looking for.

I don't want to push a button (unless I have to) - this is one step too many.

I'd like to achieve the same result as (for those who know Forms) can be done in the WHEN-VALIDATE-ITEM on the "cijena" field:
:iznos := :cijena * :litara;
and it would "fire" automatically, as soon as I leave the "cijena" field. No push buttons (i.e. no additional actions for the end user (which is me, in this case)).
Re: How to compute "a * b = c"? [message #459620 is a reply to message #459576] Mon, 07 June 2010 08:23 Go to previous messageGo to next message
delna.sexy
Messages: 941
Registered: December 2008
Location: Surat, The Diamond City
Senior Member
Put following code in page header

<script language="JavaScript" type="text/javascript">
function test(id1,id2,id3)
{
  alert(document.getElementById(id1).value);
  alert(document.getElementById(id2).value);

  $x(id3).value = parseFloat($x(id1).value) + parseFloat($x(id2).value);
}
</script>


and call that java-script function from second text box by putting following code into 'HTML form element attribute' of second text box.

onBlur="test('P2_X1','P2_X2','P2_X3');"


regards,
Delna
Re: How to compute "a * b = c"? [message #459691 is a reply to message #459620] Tue, 08 June 2010 00:42 Go to previous messageGo to next message
Littlefoot
Messages: 21580
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Marvelous, Delna! /forum/fa/2115/0/ Thank you very much!

It seems that I'll have to find JavaScripting tutorial for dummies (the sooner, the better).
Re: How to compute "a * b = c"? [message #459704 is a reply to message #459691] Tue, 08 June 2010 01:38 Go to previous messageGo to next message
Littlefoot
Messages: 21580
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
So I compared your solution with my attempt. Basically, I was on the right track, with two "minor" (right ...) modifications:
- it is not "==" but "="
- I shouldn't have used "()" brackets, but "{}" ones

It means that the following script does the job as well:

HTML (Page) Header:
<script language="JavaScript">
  function izracunaj_iznos()
    {
    $x('P22_IZNOS').value = $x('P22_LITARA').value * $x('P22_CIJENA').value;
    }
</script>

P22_CIJENA HTML Form Element Attributes:
onblur="izracunaj_iznos();"


Thank you once again; it is an unpleasant role while one acts as a newbie.

I have found an online tutorial and now I'm doing some reading on JavaScripting. Hopefully, I'll be a little bit smarter till the end of the day.

Heh, blindman. Now I payed more attention to a "This is a test" script I posted in my first message. There are too {} brackets there (instead of () ones). Gee, I should have opened both eyes ... what an idiot.

[Updated on: Tue, 08 June 2010 01:41]

Report message to a moderator

Re: How to compute "a * b = c"? [message #459735 is a reply to message #459704] Tue, 08 June 2010 02:57 Go to previous messageGo to next message
delna.sexy
Messages: 941
Registered: December 2008
Location: Surat, The Diamond City
Senior Member
Quote:
I have found an online tutorial and now I'm doing some reading on JavaScripting


/forum/fa/2115/0/

regards,
Delna
Re: How to compute "a * b = c"? [message #461624 is a reply to message #459573] Sun, 20 June 2010 01:18 Go to previous messageGo to next message
BBMamun
Messages: 94
Registered: February 2010
Location: Dhaka, Bangladesh
Member
Thanks for your beautiful illustration. You have gone a long way with the problem. I believe you want to populate the column C as we forms developers use to do..that is by using a process similar to POST-CHANGE trigger in Forms developer. To do that in Oracle Apex javascript is the solution. And al long as I have seen your javascript code it seems ok(I am also a novice in javascript). The message that you get in IE7, I think it is browser security property that prevents running the javascript. Try changing the browser setting and u can test in mozilla firefox/opera.

Regards

Hasan Al Mamun
Programmer
Bangladesh Bank
Bangladesh

[Updated on: Sun, 20 June 2010 01:18]

Report message to a moderator

Re: How to compute "a * b = c"? [message #461649 is a reply to message #461624] Sun, 20 June 2010 05:41 Go to previous messageGo to next message
Littlefoot
Messages: 21580
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
The problem is solved, as described in message #459704.
Re: How to compute "a * b = c"? [message #461660 is a reply to message #461649] Sun, 20 June 2010 12:05 Go to previous message
BBMamun
Messages: 94
Registered: February 2010
Location: Dhaka, Bangladesh
Member
Thanks for notifying. I have presumed that the javascript written is syntactically correct. So I did not actually look for the javascript syntax. You have rightly pointed out the errors and solved it. Thanks for that.

Regards

Hasan Al Mamun
Previous Topic: duplicat alias in query, but the same time none duplicats..
Next Topic: How get Current user group information
Goto Forum:
  


Current Time: Wed Aug 12 00:53:24 CDT 2020