1
0
-1

Currently I am trying to use hash variable in my javascript to calculate the date range from the selected day I picked but it doesn't work, here are my code

<script type="text/javascript">
$(input[name="start"]').change( function(){
      d1 = $('input[name="start"]').datepicker('getDate');
      d2 = #date.yyyy-MM-dd#;
      diff = 0;
      if (d1 && d2) {
            diff = Math.floor((d2.getTime() - d1.getTime()) / 86400000); // ms per day
      }
      $('input[name=testing]').val(diff);
});
</script>

so I wonder is there other approach for getting the date range?

    CommentAdd your comment...

    1 answer

    1.  
      1
      0
      -1

      Dont use 

      d2 = #date.yyyy-MM-dd#;
      
      Use

      d2 = $('input[name="start"]').datepicker('getDate');



      because hash variable can only be parsed at server side (once when you load the form from server)

      I think you want it to run everytime "start" value is changed.

      1. zyzyzy

        It works, the problem is if I set d2 datepicker to readonly, the script will become no function and I don't want the user to manipulate the date of current day.

      CommentAdd your comment...