need help w/onblur

Hi guys, the following code is meant to autoinsert the somr fields based on submission of “paidamt”.
I think the PHP code is wrong ?
[php]echo "

"; [/php] Following is the .JS [code]function $_(IDS) { return document.getElementById(IDS); } function calculate_paid() { var recur = parseInt(document.getElementById("recur").value); var pd = parseInt(document.getElementById("pd").value); var shipamt = parseFloat(document.getElementById("shipamt").value); var paidamt = parseFloat(document.getElementById("paidamt").value); var prevbal = parseFloat(document.getElementById("prevbal").value); var amtdue = parseFloat(document.getElementById("amtdue").value); var checkno = parseInt(document.getElementById("checkno").value); /* set up datepaid var datepaid = parseInt(document.getElementById("datepaid").value); var dateNow = new Date(); var dayNow = dateNow.getDate(); var datePaid = (dateNow.getMonth()+1)+"/"+dateNow.getDate()+"/"+dateNow.getFullYear(); datepaid.value = datePaid;

/* increment the check#
checkno.value = parseInt(checkno.value) + “1”;

/* if not a recurring account, adjust the “amtdue”, if total paid, PD = “p”, PREVBAL = “0.00”
if(recur.value==“N”)
{
amtdue.value = parseFloat(amtdue.value) + parseFloat(shipamt.value) - parseFloat(paidamt.value);
if(amtdue.value==“0.00”)
{ prevbal.value = “0.00”; pd=“P”; }

/* if a recurring account, adjust the “prevbal”, if total paid, PD = “p”, PREVBAL = “0.00”
prevbal.value = parseFloat(prevbal.value) + parseFloat(amtdue.value) + parseFloat(shipamt.value) - parseFloat(paidamt.value);
if(prevbal.value==“0.00”)
{ pd=“P”; }
}
[/code]

So, what is the problem. What does not work.
Do you get the other fields filled in?

Not sure what you need help with.

thanks for the response. the form is right, I can select and update but entering the PAIDAMT has no effect.
It’s like there’s no .JS file. I hope you can help?

Well, I don’t have time tonight to load a test page for you. (It’s after midnight here and got to get to bed!)

But a quick look at it shows a couple issues. First, you call it with calculate_paid(this), but you receive it with function calculate_paid()… I think the function needs to be function calculate_paid(this) also…

And, also that routine calculates the “datepaid” and “PD” but does no calculations for “datepaid”.

So, still not really understanding what you want to be shown.

Oh, and the ONBLUR only works if you the cursor is in that field box and then leaves it. So, it does not really work when you load data into that field, but, only when the user goes there and moves away. Not sure if that is what you want there. To explain a little further, PHP is server-side only. So, the data for these fields are loaded server-side and then sent to the browser. Then, the on-blur would be available.

Perhaps you can explain what you are trying to do with the “onblur” call. I can help you further in the morning, my time…

Oh, one more thing I noticed. The line “datepaid.value = datePaid;” places the data “datePaid” into the variable “datepaid”. It does not store it inside the document’s field. I think this should be more like this:
document.getElementById(“datepaid”).value = datePaid;

Bed is calling me… More tomorrow…

I really appreciate your help. There is a working version I wrote( with help from
a forum some years ago) being used by a former employer. I have since retired and
am enjoying the effect of ageing. Now I am using this (localhost) project to
keep the grey matter intact(somewhat).

I want to enter PAIDAMT & when clicking away from
that field, have the current (DATEPAID) autoinserted & based on function calcs, manipulate
CHECKNO, AMTDUE, PD & PREVBAL.

-----------------------following is current code----------------------------

[code]  function $_(IDS) { return document.getElementById(IDS); }
  function calculate_paid()
  {
  var recur = parseInt(document.getElementById("recur").value);
  var pd = parseInt(document.getElementById("pd").value);
  var shipamt = parseFloat(document.getElementById("shipamt").value);
  var paidamt = parseFloat(document.getElementById("paidamt").value);
  var prevbal = parseFloat(document.getElementById("prevbal").value);
  var amtdue = parseFloat(document.getElementById("amtdue").value);
 var checkno = parseInt(document.getElementById("checkno").value);

/* set up datepaid
var datepaid = parseInt(document.getElementById(“datepaid”).value);
var dateNow = new Date();
var dayNow = dateNow.getDate();
var datePaid = (dateNow.getMonth()+1)+"/"+dateNow.getDate()+"/"+dateNow.getFullYear();
datepaid.value = datePaid;

/* increment the check#
checkno.value = parseIntb + “1”[/b];

/* if not a recurring account, adjust the “amtdue”, if total paid, PD = “p”, PREVBAL = “0.00”
if(recur.value==“N”)
{
amtdue.value = parseFloat(amtdue.value) + parseFloat(shipamt.value) - parseFloat(paidamt.value);
if(amtdue.value==“0.00”)
{ prevbal.value = “0.00”; pd=“P”; }

/* if a recurring account, adjust the “prevbal”, if total paid, PD = “p”, PREVBAL = “0.00”
prevbal.value = parseFloat(prevbal.value) + parseFloat(amtdue.value) + parseFloat(shipamt.value) - parseFloat(paidamt.value);
if(prevbal.value==“0.00”)
{ pd=“P”; }
}[/code]
-----------------------------following is original WORKING code ---------------------------

[code]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”);

/* set up datepaid
var datepaid = document.getElementById(“datepaid”);
var late = document.getElementById(“late”);
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;

in the current (above) code, the following are decremented
instead of incremented.
************

paidsum.value = parseInt(paidsum.value) + parseInt(amtpaid.value);
tentpay.value = parseInt(tentpay.value) + parseInt(amtpaid.value) - parseInt(hudpay.value);
if(dayNow > 5) { late.value = “L”; rentdue.value = rentdue.value + 10; }

[/code]
-----------------------------following is original WORKING code ---------------------------
[php]echo "

";[/php]

-----------------------following is current code----------------------------

[php]echo "

[b] [/b] [b] [/b] "; [/php]

Well, I am heading out for a few hours, but, taking a quick peek at what you sent…

So, I will assume the and are not really in your code, but, how you copied it, correct?

Now if your calculations are correct, most of this is set up correctly. The only think is where you store the value in the “datePaid” variable into the field “datepaid”. You need to tell Javascript where t store it in the document.

So, change the line: datepaid.value = [b]datePaid;
to something like: document.getElementById(“datepaid”).value = datePaid;

Javascript will most likely read the datepaid.value as a local variable inside the Javascript.
You need to tell it that you are talking about the document’s field element.

Try that and send details of what is happening. I will look in here when I get home.

Oh, one more thing. To check the values of JS variables, you can use an “alert”.
You can add a line for testing that is like: alert(datePaid); just before you store that value.
That will create a pop-up that shows the value inside of the variable. This helps you “debug” your code.

So, check out your variables using alerts and make sure all of the steps are working correctly
and let me know if they are not. I will get back to you very late tonight.

PS: I am nearly ready for retiring, too. But, ALWAYS program… Since it was created actually! LOL…

Sponsor our Newsletter | Privacy Policy | Terms of Service