I need help with this script

Discussion in 'JavaScript' started by ckdoublenecks, Dec 28, 2010.

  1. #1
    Can someone help me with this? Nothing works beyond the // *############

    <script>
    function $_(IDS) { return document.getElementById(IDS); }
    function calculate_paid() {
       var amtpaid = document.getElementById("amtpaid");
       var rentdue = document.getElementById("rentdue");
     var prevbal = document.getElementById("prevbal");
    var hudpay = document.getElementById("hudpay");
    var tentpay = document.getElementById("tentpay");
     var datepaid = document.getElementById("datepaid");
     var late = document.getElementById("late");
     var damage = document.getElementById("damage");
     var courtcost = document.getElementById("courtcost");
     var nsf = document.getElementById("nsf");
    var latechg = document.getElementById("latechg");
     var secdep = document.getElementById("secdep");
      var paidsum = document.getElementById("paidsum");
      var dateNow = new Date();
      var dayNow = dateNow.getDate();
      var datePaid = (dateNow.getMonth()+1)+"/"+dateNow.getDate()+"/"+dateNow.getFullYear();
    datepaid.value = datePaid;
    // ***************************************************************************************
    // * if paid later than the 5th of the month, insert an "L" in the late field and add 10 the the rentdue 
    // *************************************************************************************** 
                  if(dayNow > 5) { late.value = "L"; rentdue = rentdue + 10; }
    // ***************************************************************************************
    // * add the amtpaid (current) to any previous payments (paidsum)
    // *************************************************************************************** 
                  paidsum.value = parseInt(paidsum.value) + parseInt(amtpaid.value);
    // ***************************************************************************************
    // * tentpay = amtpaid - hudpay
    // ***************************************************************************************
                 tentpay.value = parseInt(tentpay.value) + parseInt(amtpaid.value) - parseInt(hudpay.value);
    // ##############################################################
    // * totOwed = everything = everything owed
    // ***************************************************************************************
              var totOwed = parseInt(rentdue.value) + parseInt(prevbal.value) + 
    parseInt(secdep.value) + parseInt(damage.value) + parseInt(latechg.value) + 
    parseInt(courtcost.value) + parseInt(nsf.value) - parseInt(hudpay.value);
    // ***************************************************************************************
    // * stillOwed = what is still owed after the payment(amtpaid)
    // ***************************************************************************************
              var stillOwed = totOwed - parseInt(amtpaid.value);
    // ***************************************************************************************
    // * if an excess has been paid, prevbal will be a minus amt & all previous chgs will be zero
    // ***************************************************************************************
           if (amtpaid.value >= totOwed) { prevbal.value = totOwed - amtpaid.value; secdep.value = 0; 
           damage.value = 0; latechg.value = 0; courtcost.value = 0; nsf.value = 0;}
    // ***************************************************************************************
    // * if money is still owed, pay in order-prevbal,secdep,damage,latechg,courtcost,nsf
    // * until payment is exhausted
    // ***************************************************************************************
    if (stillOwed >= prevbal.value) {stillOwed = stillOwed - prevbal.value; prevbal.value = 0;}
    if (stillOwed > 0) {prevbal.value = prevbal.value - stillOwed; stillOwed = 0;}
    if (stillOwed >= secdep.value) {stillOwed = stillOwed - secdep.value; secdep.value = 0;}
    if (stillOwed > 0) {secdep.value = secdep.value - stillOwed; stillOwed = 0;}
    if (stillOwed >= damage.value) {stillOwed = stillOwed - damage.value; damage.value = 0;}
    if (stillOwed > 0) {damage.value = damage.value - stillOwed; stillOwed = 0;}
    if (stillOwed >= latechg.value) {stillOwed = stillOwed - latechg.value; latechg.value = 0;}
    if (stillOwed > 0) {latechg.value = latechg.value - stillOwed; stillOwed = 0;}
    if (stillOwed >= courtcost.value) {stillOwed = stillOwed - courtcost.value; courtcost.value = 0;}
    if (stillOwed > 0) {courtcost.value = courtcost.value - stillOwed; stillOwed = 0;}
    if (stillOwed >= nsf.value) {stillOwed = stillOwed - nsf.value; nsf.value = 0;}
    if (stillOwed > 0) {nsf.value = nsf.value - stillOwed; stillOwed = 0;}
    }
    </script>
    Code (markup):
     
    ckdoublenecks, Dec 28, 2010 IP
  2. shofstetter

    shofstetter Well-Known Member

    Messages:
    178
    Likes Received:
    7
    Best Answers:
    1
    Trophy Points:
    120
    #2
    What web browser do you use?

    if in internet explorer click on the little triangle icon and post the error message.

    if Firefox click Tools->error console and post the output

    I will examine your code, but the error messages if any would be very helpful.

    BTW if your input uses decimals then you should use parseFloat() not parseInt().
     
    Last edited: Dec 28, 2010
    shofstetter, Dec 28, 2010 IP
  3. ckdoublenecks

    ckdoublenecks Guest

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for your input. there are no error messages and no decimals. When I enter the amtpaid the datepaid(current date), tentpay, "L"(late) & paidsum are inserted. None of the other fields are inserted. I imagine there are better ways to code this.
     
    ckdoublenecks, Dec 29, 2010 IP