0 votes
1 view
in Salesforce by (11.3k points)

Hi all,

  <script type="text/javascript">

          function duedatecal(){

            var invoicedate = $(".invoicedate").val();

             var paymentterms = $(".paymentterms").html();

          }

        </script>

        <apex:form>

        Date:

         <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

        </apex:form>

Whenever I change the inputtext(of Date) the duedate should be displayed accordingly by adding Date+payment Days. Help on this pls

1 Answer

0 votes
by (28.6k points)

Try the following code to solve this problem:

function duedatecal(){

    var dmy = $(".invoicedate").val().split("/");        

    var invoicedate = new Date(

                   parseInt(dmy[2], 10),

                   parseInt(dmy[0], 10) - 1,

                   parseInt(dmy[1], 10)

                 );

    var paymentterms = $(".paymentterms").text();

    var dueDate = new Date();

    dueDate.setDate(invoicedate.getDate()+parseInt(paymentterms));

    var duedates = dueDate.getDate()+"/"+(dueDate.getMonth()+1)+"/"+dueDate.getFullYear();

    $(".duedate").html(duedates);

}

...