JavaScript help needed for summing fields

Discussion in 'General Computer Support' started by Ollie 3rd, Jan 17, 2010.

  1. Ollie 3rd

    Ollie 3rd

    Joined:
    Jan 17, 2010
    Messages:
    1
    I am pulling my hairs out (both of them) trying to get this to work. I am trying to sum entries in 6 form blocks and have the results show in the 7th block so I can Post all 7 blocks to a MySql database. The posting part is working but for the love of me I can't get the addition to work.

    <script type="text/javascript">
    <!-- Begin
    function startCalc()
    {
    interval = setInterval("calc()",1);
    }
    function calc()
    {
    one = document.getElementByName('field_24'Value);
    two = document.getElementByName('field_25'Value);
    three = document.getElementByName('field_26'Value);
    four = document.getElementByName('field_27'Value);
    five = document.getElementByName('field_28'Value);
    six = document.getElementByName('field_29'Value);
    document.getElementByName('field_30')= (one * 1) + (two * 1) + (three * 1) + (four * 1) + (five * 1) + (six * 1);
    }
    function stopCalc()
    {
    clearInterval(interval);
    }
    // End -->
    </script>

    <body onLoad="collapseAll()">

    <div id="mainForm">




    <div id="formHeader">
    <h2 class="formInfo">Report Entry Form</h2>
    <p class="formInfo">Towing Report Entry Form</p>
    </div>


    <BR/><!-- begin form -->
    <form method=post enctype=multipart/form-data action=processor.php onSubmit="return validatePage1();"><ul class=mainForm id="mainForm_1"><input type=hidden name=field_1 id=field_1 value="">


    <li class="mainForm" id="fieldBox_24">
    <label class="formFieldQuestion">Towing Charge&nbsp;*&nbsp;<a class=info href=#><img src=imgs/tip_small.png border=0><span class=infobox>Enter the amount of the towing charge</span></a></label><input class=mainForm type=text name=field_24 id=field_24 size='20' value='' onFocus="startCalc();" onBlur="stopCalc();"></li>

    <li class="mainForm" id="fieldBox_25">
    <label class="formFieldQuestion">Winching Charge&nbsp;<a class=info href=#><img src=imgs/tip_small.png border=0><span class=infobox>Enter the charge for winching</span></a></label><input class=mainForm type=text name=field_25 id=field_25 size='20' value='' onFocus="startCalc();" onBlur="stopCalc();"></li>

    <li class="mainForm" id="fieldBox_26">
    <label class="formFieldQuestion">Labor Charge&nbsp;<a class=info href=#><img src=imgs/tip_small.png border=0><span class=infobox>Enter the amount of any labor charges</span></a></label><input class=mainForm type=text name=field_26 id=field_26 size='20' value='' onFocus="startCalc();" onBlur="stopCalc();" ></li>

    <li class="mainForm" id="fieldBox_27">
    <label class="formFieldQuestion">Storage Charge&nbsp;<a class=info href=#><img src=imgs/tip_small.png border=0><span class=infobox>Enter the total amount of the storage charge</span></a></label><input class=mainForm type=text name=field_27 id=field_27 size='20' value='' onFocus="startCalc();" onBlur="stopCalc();"></li>

    <li class="mainForm" id="fieldBox_28">
    <label class="formFieldQuestion">2ND Towing Charge&nbsp;<a class=info href=#><img src=imgs/tip_small.png border=0><span class=infobox>Enter the charge for the 2nd tow</span></a></label><input class=mainForm type=text name=field_28 id=field_28 size='20' value='' onFocus="startCalc();" onBlur="stopCalc();"></li>

    <li class="mainForm" id="fieldBox_29">
    <label class="formFieldQuestion">Other Charges&nbsp;<a class=info href=#><img src=imgs/tip_small.png border=0><span class=infobox>Enter the amount of any additional charges</span></a></label><input class=mainForm type=text name=field_29 id=field_29 size='20' value='' onFocus="startCalc();" onBlur="stopCalc();"></li>

    <li class="mainForm" id="fieldBox_30">
    <label class="formFieldQuestion">Total Charges&nbsp;*&nbsp;<a class=info href=#><img src=imgs/tip_small.png border=0><span class=infobox>Enter total amount to be billed</span></a></label><input class=mainForm type=text name=field_30 id=field_30 size='20' value=''></li>


    <!-- end of this page -->
     
    Ollie 3rd, Jan 17, 2010
    #1
    1. Advertising

  2. Ollie 3rd

    Trikster

    Joined:
    Jan 19, 2010
    Messages:
    3
    Try this:

    Code:
    function calc() {
      var fields = Array(), total, i;
    
      fields[0] = document.forms[0].field_24.value;
      fields[1] = document.forms[0].field_25.value;
      fields[2] = document.forms[0].field_26.value;
      fields[3] = document.forms[0].field_27.value;
      fields[4] = document.forms[0].field_28.value;
      fields[5] = document.forms[0].field_29.value;
      for (i = 0; i < 6; i++) total += parseInt(fields[i]);
    
      document.forms[0].field_30.value = total;
    }
    I hope this helps!
     
    Trikster, Jan 19, 2010
    #2
    1. Advertising

  3. Ollie 3rd

    elizas

    Joined:
    Jan 27, 2010
    Messages:
    2
    Location:
    India
    Javascript needed for mysql

    In MYSQL GROUP BY provide us a modifier called WITH ROLLUP, which will added an extra row to the output as a summary report.


    For Example:

    Suppose we have a Sales table having SalesId, ContactId and SalesTotal. If we need a summary report, which will display total SalesTotal group by its ContactId.
    This can be done using a simple query:

    SELECT IFNULL(`ContactId` , "GRAND TOTAL") AS 'CONTACT ID', SUM(`SalesTotal`) AS `TOTAL` FROM Sales GROUP BY `ContactId` WITH ROLLUP
    Output:

    CONTACT ID TOTAL
    117 5
    118 0
    119 10
    GRAND TOTAL 15

    You can't use the ORDER BY clause with the WITH ROLLUP. They are mutually exclusive.
    It may not be the exact solutions to the problem.but it is a similar one.Check if it helps.

    thanks
     
    elizas, Jan 27, 2010
    #3
  4. Ollie 3rd

    elizas

    Joined:
    Jan 27, 2010
    Messages:
    2
    Location:
    India
    Post Data from One form to other form using Cross-Page techiniuqe in ASP.NET 2.0

    To post data from one webpage to another webpage we need to take the help of @ PreviousPageType directive which can be used with one of the following attributes TypeName and VirtualPath The following line of code shows how to use the directive with VirtualPath attribute <%@ PreviousPageType VirtualPath="~/Sample1.aspx" %> , from which we can get the refernce of the previous page controls using FindControl() method.

    To explain this process we need to take two sample web pages such as Sample1.aspx and Sample2.aspx. Then in Sample1.aspx page create some text boxes for user input and a Submit button to post data to the Sample2.aspx page.
     
    elizas, Mar 29, 2010
    #4
  5. Ollie 3rd

    farneville

    Joined:
    Apr 6, 2010
    Messages:
    15
    looks complicated use batch script rather. It's more simple I will try to come up with a code and be back once done :)
     
    farneville, Apr 6, 2010
    #5
  6. Ollie 3rd

    eliza81

    Joined:
    Feb 10, 2010
    Messages:
    1
    Post Data from One form to other form using Cross-Page techiniuqe in ASP.NET 2.0

    To post data from one webpage to another webpage we need to take the help of @ PreviousPageType directive which can be used with one of the following attributes TypeName and VirtualPath The following line of code shows how to use the directive with VirtualPath attribute <%@ PreviousPageType VirtualPath="~/Sample1.aspx" %> , from which we can get the refernce of the previous page controls using FindControl() method.
     
    eliza81, Jun 7, 2010
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Um9iIEI=?=

    can electrical fields block wireless transfer?

    =?Utf-8?B?Um9iIEI=?=, Nov 14, 2005, in forum: Wireless Networking
    Replies:
    2
    Views:
    615
    Pavel A.
    Nov 14, 2005
  2. Gary Cox

    Password fields can be copied

    Gary Cox, Oct 12, 2004, in forum: Firefox
    Replies:
    2
    Views:
    1,856
    Gary Cox
    Oct 13, 2004
  3. Shane

    To Javascript, or not to Javascript

    Shane, Aug 29, 2005, in forum: NZ Computing
    Replies:
    5
    Views:
    554
    Waylon Kenning
    Aug 30, 2005
  4. Giuen
    Replies:
    0
    Views:
    1,419
    Giuen
    Sep 12, 2008
  5. cloucas
    Replies:
    2
    Views:
    3,879
    globsada
    Oct 19, 2012
Loading...

Share This Page