You are viewing limited content. For full access, please sign in.

Question

Question

How to write JavaScript with date comparisons

asked on October 5, 2018

Good Morning,

I really need some help and I have very little experience with JavaScript and my "go to" person is out on maternity leave. 

We are sending out a public notice and in this notice, we have to incorporate a link for the "Public Comment" form that can be used to submit comments.  To do this, I have utilized the business process from the Laserfiche Forms library.    My problem arises with the fact that I do not want the submit button to work unless the current date is equal to or between the start and end date.

I can find all kinds of code with different pieces but without a background in javascript, I am at a loss on how to put it together and make it work.

Can anyone help me with this issue?

 

0 0

Answer

SELECTED ANSWER
replied on October 5, 2018

Hi Beverly,

 

Are the users entering the start and end dates? If this is the case, something like this might work:

$(document).ready(function() {
  // The startDate and endDate selectors will be different for you.
  var $startDate = $("#Field1");
  var $endDate = $("#Field2");
  var $submit = $(".Submit");
  
  $startDate.add($endDate).on(
    "change",
    function() {
      // Create moment objects for the start, end, and current dates
      var startDate = moment($startDate.val());
      var endDate = moment($endDate.val());
      var currentDate = moment();

      if (!currentDate.isBetween(startDate, endDate)) {
        $submit.hide();
      } else {
        $submit.show();
      }
    }
  );
});

Note that your start and end date selectors will probably be different.

2 0
replied on October 8, 2018

You are wonderful.  Thank worked great!

1 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.