<script type="text/javascript">
 function duedatecal(){
 var dmy = $(".invoicedate").val().split("/");     
  alert(dmy);  // it is in the format of mm/dd/yyyy 
var invoicedate = new Date(
               parseInt(dmy[2], 10),
               parseInt(dmy[1], 10) - 1,
               parseInt(dmy[0], 10)
alert(invoicedate.getDate()); //Getting the month Value but need to get the date value
var paymentterms = $(".paymentterms").text();
var dueDate = new Date();
dueDate.setDate(invoicedate.getDate()+parseInt(paymentterms)); //need to add paymentterms to date but here adding to the month
$(".duedate").html(dueDate);  //not getting the output displayed

         <Apex:inputtext value="{!dateIn}" id="time" styleclass="invoicedate" onblur="duedatecal();"/> //say suppose date is 06/03/2013
        Payment Days:
           <apex:outputtext value="{!payment.Net__c}" styleclass="paymentterms"  /> //say suppose will get 10 days here
        Due date:
           <apex:outputtext value="{!duedate}" styleclass="duedate"/> // output shld be 16/03/2013

Here the {!duedate} is not getting displayed in the outputtext(Added all the errors I'm facing in javascript code).Where I went wrong?


It works for me. I've just formatted the date to the 'MM/DD/YYYY', used jQuery syntax instead of '$' and some of javascript date functions like parse:

function duedatecal(){
    var invoicedate = new Date(Date.parse(jQuery(".invoicedate").val()));
    invoicedate.setDate(invoicedate.getDate() + parseInt(jQuery(".paymentterms").text()));
    jQuery(".duedate").html((invoicedate.getMonth()+1) + '/' +invoicedate.getDate() + '/' + invoicedate.getFullYear());  

The result:

enter image description here

|improve this answer|||||
  • edited my code.Can u check it once – Eagerin Sf Jun 3 '13 at 14:55
  • @EagerinSf I've updated my example – Sergej Utko Jun 3 '13 at 18:33
  • here 06/03/2013 is in mm/dd/yyyy format.I need to add payment days to date but not to month like 06/03/2013 + 10 = 06/13/2013 help Pls – Eagerin Sf Jun 4 '13 at 6:14
  • @EagerinSf Ok, updated the code again. Try it and if it is ok then rate my answer. – Sergej Utko Jun 4 '13 at 7:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.