0

I've done some searches but couldn't find anything similar.

I need to disable/enable the submit button based on dates. For example, I need the submit button to be disabled during weekends and enabled during weekdays. Also, I need to create either a pop-up or add line of text to say something like "we are not accepting entries during weekends."

Thanks!

Chun
  • 5
  • 4

1 Answers1

1

Is this what you had in mind? This will add a class of disabled to a button if it's Saturday or Sunday.

$(function() {
  var now = new Date(),
      days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'],
      day = days[now.getDay()],
      $button = $('#myButton');
  
  if (day === days[0] || day === days[6]) {
      $button.addClass('disabled');
  }
  
  $button.click(function() {
      if ($(this).hasClass('disabled')) {
          alert('We are not accepting entries during weekends.')
          return;
      }
  });
})
.disabled {
  background: grey;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="myButton">Press me only on weekday</button>
divix
  • 1,265
  • 13
  • 27
  • Thanks! How would I change this to have the button disabled based on the actual dates (i.e. YYYY/MM/DD)? – Chun Dec 03 '15 at 13:20