1
0
-1

Hi Experts,

I want to calculate duration between two dates: cpo_cpo_date and cpo_cpo_req_date using custom HTML.

Unfortunately no luck when I try to preview, any idea?

APP_date_test-1-20160325142851.jwa

<script type="text/javascript">
$('input[name="cpo_cpo_date"], input[name="cpo_cpo_req_date"]').change( function(){
d1 = $('input[name="cpo_cpo_date"]').datepicker('getDate');
d2 = $('input[name="cpo_cpo_req_date"]').datepicker('getDate');
diff = 0;
if (d1 && d2) {
diff = Math.floor((d2.getTime() - d1.getTime()) / 86400000); // ms per day
}
$('input[name=days]').val(diff);
});
</script>

BR,

Sylwester

 

    CommentAdd your comment...

    1 answer

    1.  
      1
      0
      -1

      i tried ur code, look like u need to put it in as following. u attached the change event to an element tht haven't exist.

      <script>
      $(document).ready(function(){
          $('input[name="cpo_cpo_date"], input[name="cpo_cpo_req_date"]').change( function(){
                d1 = $('input[name="cpo_cpo_date"]').datepicker('getDate');
                d2 = $('input[name="cpo_cpo_req_date"]').datepicker('getDate');
                diff = 0;
                if (d1 && d2) {
                      diff = Math.floor((d2.getTime() - d1.getTime()) / 86400000); // ms per day
                }
                $('input[name=days]').val(diff);
          });
      });
      </script>
        CommentAdd your comment...