Results 1 to 2 of 2

Thread: Auto calculate the subtraction of total earn and total deduction

  1. #1
    Join Date
    Oct 2011
    Posts
    39
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Auto calculate the subtraction of total earn and total deduction

    Good day!


    I am new in javascript function.

    I have Javascript code for auto calculate

    here is the code:
    Code:
    <script type="text/javascript" language="javascript">
    
    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
    }
    }
    var tot=Number(TotEarn) + Number(document.getElementById('Amount').value);
    oForm.TotEarn.value = tot.toFixed(2);
    //oForm.TotEarn.value = TotEarn.toFixed(2); //out
     
    }
    
    </script>
    <!--Total Deduction AutoCompute-->
    <script type="text/javascript" language="javascript">
    
    function autocalded(oText)
    {
    if (isNaN(oText.value)) //filter input
    {
    alert('Numbers only!');
    oText.value = '';
    }
    var field, val, oForm = oText.form, TotalDed = 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?
    {
    TotalDed += val; //accumulate
    }
    }
    //oForm.TotalDed.value = TotalDed.toFixed(2); //out
    
    var totded=Number(TotalDed) + Number(document.getElementById('Deductions').value);
    oForm.TotalDed.value = totded.toFixed(2);
    }
    
    </script>
    and now my problem is...I have a textbox for the overall total, and i want it automatic subtract the total earn and total deduction..

    I will attach my codes for further understanding.

    Thank you in advance

  2. #2
    Join Date
    Oct 2011
    Posts
    39
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default

    Theres a programmer help me to display and subract the total earn and total deduction, the only problem now is when I add data in total earn it did not add in Over all total.. the only good happen is when I add deductions it take it takes effect or subtract in over all total..

    Like for example I add total earn from 1000 i add 20 the total earn become 1020 but the overall total still 100 but when i add also deduction from 100 I add 10 the overall total become 910 which is correct. I only want is when the total earn was change also the overall total will also change..

    Thank you

    here is the revise code:
    Code:
    <script type="text/javascript">
    var tot;
    function autocalearn(oText)
    {
    if (isNaN(oText.value)) 
    {
    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)) 
    {
    TotEarn += val; 
    }
    }
    
    tot=Number(TotEarn) + Number(document.getElementById('Amount').value);
    oForm.TotEarn.value = tot.toFixed(2);
    }
    
    function autocalded(oText)
    {
    if (isNaN(oText.value))
    {
    alert('Numbers only!');
    oText.value = '';
    }
    var field, val, oForm = oText.form, TotalDed = a = 0;
    for (a; a < arguments.length; ++a) //loop through text elements
    {
    field = arguments[a];
    val = parseFloat(field.value); 
    if (!isNaN(val)) //number?
    {
    TotalDed += val; 
    }
    }
    
    
    var totded=Number(TotalDed) + Number(document.getElementById('Deductions').value);
    oForm.TotalDed.value = totded.toFixed(2);
    var overallTotal = tot - totded;
    
    oForm.TakeHomePay.value = overallTotal.toFixed(2); 
    }
    
    </script>
    Thank you

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
  •