Reputation: 5
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!
Upvotes: 0
Views: 1229
Reputation: 1364
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>
Upvotes: 1