SitePoint Sponsor

User Tag List

Results 1 to 1 of 1
  1. #1
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    658
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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
    Attached Files Attached Files


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
  •