Results 1 to 2 of 2

Thread: Javascript and php code for autocalculation

  1. #1
    Join Date
    Jul 2010
    Posts
    228
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Default Javascript and php code for autocalculation

    Hi!


    I used javascript for my autocalculate and it works and now my problem is how can I SUM the total from autocalculate and the Data from other textbox.

    here is my code:

    Code:
    function autocalearn(oText)
    {
    if (isNaN(oText.value)) //filter input
    {
    alert('Numbers only!');
    oText.value = '';
    }
    var field, val, oForm = oText.form, TotEarn = a = 0;
    for (a; a < arguments.length; ++a) //loop through text elements
    {
    field = arguments[a];
    val = parseFloat(field.value); //get value
    if (!isNaN(val)) //number?
    {
    TotEarn += val; //accumulate
    }
    }
    oForm.TotEarn.value = TotEarn.toFixed(2); //out
    }
    
    </script>
    The scenario is I have a Amount textbox and it has a value from database. And I have textboxes which is autocalculate and the total of that is display in total earn and now i want that the total earn and total amount will SUm and display in total earn..

    PHP Code:
    <input name"Amount" class = "LFieldTot" type="text" maxlength="12" tabindex="0" size="12" value="{$Amount}readonly="readonly"/> 
    Thank you...

    I tried to put {Amount} in Total Earn Values but when I insert data in the earnings textbox the data was the calculate from the textboxes, it did not sum the Amount.

  2. #2
    Join Date
    Jul 2010
    Posts
    228
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Default

    Good day!

    I tried to edit the codes and i want to happen is the value of textbox amount will add also in the autocalculated.

    here is the code:
    PHP Code:
    <script type="text/javascript" language="javascript">

    function 
    autocalearn(oText)
    {
    if (
    isNaN(oText.value)) //filter input
    {
    alert('Numbers only!');
    oText.value '';
    }
    var 
    fieldvaloForm oText.formTotEarn 0;
    for (
    aarguments.length; ++a//loop through text elements
    {
    field arguments[a];
    val parseFloat(field.value); //get value
    if (!isNaN(val)) //number?
    {
    TotEarn += val//accumulate
    }
    }
    //oForm.TotEarn.value = TotEarn.toFixed(2); //out
    oForm.TotEarn.value TotEarn.toFixed(2) + document.getElementById('Amount').value;
    }

    </script> 
    the output of this code is when I input 10 the amount data is 100 the total earn is 10100..its wrong..I want result is 110.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •