Click here to Skip to main content
16,021,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
function checkLimit()
{
      db=openDatabase(masterDbName,version,displayName,maxSize);
     db.transaction(function(transaction)
      {
       var active=localStorage.getItem("ActiveProject");
       var query='Select projdb_id from projecttable where proj_name="'+active+'"';
       transaction.executeSql(query, [] , function(transaction, result)
        {
          if(result != null && result.rows != null)
            {
            if (result.rows.length != 0)
             {
              for (var i = 0; i < result.rows.length; i++)
               {
                 var row = result.rows.item(i);
                 id=row.projdb_id;
               }
             }
           }
        db1=openDatabase(id,version,displayName,maxSize);
  db1.transaction(function (t)
    {
     var query='Select * from customer  where cust_name="'+document.getElementById('name').value+'"';
       t.executeSql(query, [] , function(t, result)
        {
        if(result != null && result.rows != null)
            {
          if (result.rows.length != 0)
            {
            for (var i = 0; i < result.rows.length; i++)
             {
             var row = result.rows.item(i);
             var period=row.credit_period;           //period value from customer table
             }
             var myDate=new Date(document.getElementById('date').value),
             curr_month=("0"+(myDate.getMonth()+1)).slice(-2),
             day=("0"+myDate.getDate()).slice(-2);
            }
            }
                 var queryIn = 'SELECT date_format FROM  params ';
                var listArry =[];
                db.transaction(function (tx)
            {
            tx.executeSql(queryIn, [], function (tx, results)
            {
              var len = results.rows.length, i;
          if(results != null && results.rows != null)
            {
             if (results.rows.length != 0)
              {
                for (var i = 0; i < results.rows.length; i++)
                 {
                 var row = results.rows.item(i);
                 var dateformat=row.date_format;
                 }
                 var formDate;
                 if(dateformat=="dd/mm/yyy")
                 {
                    formDate= day+"/"+curr_month + "/" +myDate.getFullYear();
                 }
                 else
                 {
                 formDate= curr_month+"/"+myDate + "/" +myDate.getFullYear();
                  }
              }
            }
                 var dated=formDate.getDate()+period;
             expDate = dated;
             document.getElementById('due_date').value=expDate;
	});
			  });
			
		});
	});
		});
	  });
}


This is my code to get the format of the date and calculate the credit period and display the date according to that in textbox.I have a date field from where the user will enter the date and according to the date entered the due_date field should change by addding the credit period value..

for example if the date is 03/06/2014 and the credit limit is 10 days...then 13/06/2014 should be the due date value..
How can I do this....The above code var dated=formDate.getDate()+period; shows the error undefined function..

Plz help!!!
Posted
Updated 3-Jun-14 0:22am
v4
Comments
What is that period value? Debug and tell me.
p@y@l 3-Jun-14 6:23am    
according to the example given 10 will be period value..
And what is the value of formDate.getDate()?
p@y@l 3-Jun-14 6:32am    
I dont get any value there..it is undefined..I guess this is not the way..i got the asnwer for it posted below..
Okay, cool. Good work. :)

I have explained the problem in my answer. See it.

formDate=myDate.add(period).days();
Use add() method defined in date.js file..include this date.js in our html file.
 
Share this answer
 
The thing is formDate was not a Date object, it was a string. And you are calling getDate() method of Date object.

That's why it was undefined.
 
Share this answer
 
Comments
p@y@l 3-Jun-14 6:50am    
ohh....ok...:) thank you...it worked well..
Welcome. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900