0

can someone help 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>
3
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by ckdoublenecks
0

One of the things that jump out at me in particular is this line:

rentdue = rentdue + 10;

You define rentdue as a DOM element then you assign it itself plus 10. This won't ever work. If you want to put the value inside the input box (guessing that's the element as I don't have your html) then you will need to do:

rentdue.value = parseInt(rentdue.value) + 10;

Other than that more precise description of what you are having issues with would be helpful (ie I give it this input but get this output or I'm getting this error).

0

Please also include your HTML. Where you say it fails is early enough in the code around where you're initializing your variables. Most likely you're trying setting an undefined variable and it's throwing off.

Also, be aware that with parseInt, if the argument is invalid, it will throw a NaN, so make sure you have valid numeric strings (e.g. "45", " 56", "506x" and NOT "x45"). Another reason we need to see the HTML.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.