6 Replies Latest reply: Nov 3, 2007 4:30 PM by 135285 RSS

    tabular form calculation conundrum

    orsteve
      OK - I have successfully used the forum's suggested code for calculating a value and putting it into a tabular form column...but today is one of those days where I "don't see" the problem.

      Several updateable report columns displayed - four are considered "editable": the ID column (not shown), unit_price (text field), multiplier (display as text save state), and total_bid (display as text save state).

      I have this in the unit_price element attribute field: onChange="javascript:calcItems();"

      I have the calcItems function in the page header (added spaces around the i to avoid showing italics):

      <script type="text/javascript">
      function calcItems(){
      for (i=0; i<document.wwv_flow.f01.length; i++)
      {
      price = parseFloat(document.wwv_flow.f02[ i ].value);
      multiplier = parseFloat(document.wwv_flow.f03[ i ].value);
      total_bid = price*multiplier;
      document.wwv_flow.f04[ i ].value = parseFloat(total_bid);
      }
      }
      </script>

      You might see a > before the </script> but it isn't in my code - must be somehow created by the message editor...

      The total_bid (f04) column never changes when the unit_price changes.

      Anyone see something obvious?

      Thanks,
      Steve
        • 1. Re: tabular form calculation conundrum
          orsteve
          Bump... It is almost like the function isn't being called

          Steve
          • 2. Re: tabular form calculation conundrum
            135285
            Hi,

            if you think the function isn't call add a
            alert('hallo');
            to your function.

            But I think it's something different. As a test, try to change the column type of "total_bid" to a "text field". When you look at the HTML code of you page you will see that total_bid is a hidden column, it has nothing to do with the displayed value which is just plain HTML text.

            Patrick
            ----------------------------------------------------------------------------------------------------
            My APEX Blog: http://inside-apex.blogspot.com
            The ApexLib Framework: http://apexlib.sourceforge.net
            The APEX Builder Plugin: http://sourceforge.net/projects/apexplugin/
            • 3. Re: tabular form calculation conundrum
              orsteve
              Patrick,

              Changing to text field didn't make a difference.

              Used the alert and saw the message when I put it right after the function line but when I moved it inside the for loop it didn't fire. Doesn't this mean that the

              for (i=0; i<document.wwv_flow.f01.length; i++)

              doesn't see any rows?

              Thanks,
              Steve
              • 4. Re: tabular form calculation conundrum
                135285
                Do you have a row-selector checkbox for your tabular form? If not, f01 might not be used.

                Just use a field for the loop which you actually access. eg. f02

                Patrick
                ----------------------------------------------------------------------------------------------------
                My APEX Blog: http://inside-apex.blogspot.com
                The ApexLib Framework: http://apexlib.sourceforge.net
                The APEX Builder Plugin: http://sourceforge.net/projects/apexplugin/
                • 5. Re: tabular form calculation conundrum
                  orsteve
                  Tried f02 - didn't work. Then tried the code below (set a var col1) and that at least got the alert to fire. But when I moved the alert after the 'price =' line it didn't fire. I am at a loss as to what to try next...

                  Thanks,
                  Steve


                  function calcItems()
                  {
                  var col1 = document.getElementsByName('f01');

                  for (i=0; i<col1.length; i++) {
                  alert('hallo');
                  price = parseFloat(document.wwv_flow.f02[ i ].value);
                  multiplier = parseFloat(document.wwv_flow.f03[ i ].value);
                  var total_bid = price*multiplier;
                  document.wwv_flow.f04[ i ].value = parseFloat(total_bid);
                  }
                  }
                  • 6. Re: tabular form calculation conundrum
                    135285
                    Steve,

                    can you create an example on apex.oracle.com. Because I tried it with your example code and everything worked fined in my test case.

                    Patrick
                    ----------------------------------------------------------------------------------------------------
                    My APEX Blog: http://inside-apex.blogspot.com
                    The ApexLib Framework: http://apexlib.sourceforge.net
                    The APEX Builder Plugin: http://sourceforge.net/projects/apexplugin/