Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NaN js issue

Status
Not open for further replies.

Bastien

Programmer
May 29, 2000
1,683
0
0
CA
I have the below code

Code:
      function calcPromissory()
      {
        var tmpStart = document.getElementById('case_promissory_start').value; 
        var tmpTerm  = document.getElementById('CASE.PROMISSORY_TERM').value; 
        var tmpAmt   = document.getElementById('CASE.PROMISSORY_AMT').value;
        var tmpEDate = document.getElementById('row_promissory_end_date');

        if ( isNaN(tmpTerm) || isNaN(tmpAmt) || tmpTerm == 0 || tmpAmt == 0 ) {return;}
        if ( tmpStart == ''){return};
        if (!CheckFieldDate("case_promissory_start", tmpStart)){ return; }
        
        var arrDt = tmpStart.split("/");
        if (arrDt.len < 3){ alert("Start Date is not a valid date"); return; }
        if (tmpTerm > 11){
          var addYears = Math.floor(tmpTerm/12);
          var addMonths = tmpTerm % 12;
        }
        
        var EndYear  = Math.abs(arrDt[2]);
            EndYear  = EndYear + addYears;
        var EndMonth = Math.abs(arrDt[0]);   
            EndMonth = EndMonth + addMonths;
            
        alert(EndMonth);    
        if(EndMonth > 11){
          EndYear = EndYear + 1;
          EndMonth = EndMonth-11;
        }
alert(EndMonth);
        var month=new Array(12);
        month[0]="January";
        month[1]="February";
        month[2]="March";
        month[3]="April";
        month[4]="May";
        month[5]="June";
        month[6]="July";
        month[7]="August";
        month[8]="September";
        month[9]="October";
        month[10]="November";
        month[11]="December";
        
        var dUpdatePayAmount = document.getElementById('row_promissory_payment_amt');
        var nAmtVal = Math.round(tmpAmt / tmpTerm * 100)/100  ;
        dUpdatePayAmount.innerHTML = '$' + nAmtVal; 
        tmpEDate.innerHTML = month[EndMonth] + ' / ' + EndYear;

and both EndMonth and EndYear are not being nice, coming out as undefined and NaN. I can guess that its somewhere in the code that does the calculation as below

Code:
        var EndYear  = Math.abs(arrDt[2]);
            EndYear  = EndYear + addYears;
        var EndMonth = Math.abs(arrDt[0]);   
            EndMonth = EndMonth + addMonths;
            
        alert(EndMonth);    
        if(EndMonth > 11){
          EndYear = EndYear + 1;
          EndMonth = EndMonth-11;
        }

Anyone wanna point out where I made my mistake?

Bastien

I wish my computer would do what I want it to do,
instead of what I tell it to do...
 
What's inside tmpStart? And in arrDt? Why are you computing the absolute value of a year and a month number?

Cheers,
Dian
 
Its a date passing into the code from case_promissory_start which is a US formatted date e.g., 10/31/2008

Bastien

I wish my computer would do what I want it to do,
instead of what I tell it to do...
 
>if (arrDt.len < 3){
[tt]if (arrDt.len[red]gth[/red] < 3){[/tt]

The rest, the logic seems shaky at places; just can't be sure for a lot of things to point out...
 
As well as the ".len" typo tsuji spotted, you might also need to use "parseInt(str, 10)" to convert your strings to numbers in some cases.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Thanks, guys...that made a difference...

Bastien

I wish my computer would do what I want it to do,
instead of what I tell it to do...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top