mardi 17 octobre 2017

Disable Checkbox on Certain Date? JavaScript

I'm trying to see if I can disable a checkbox on a form on two certain days of the week, say if I want the checkbox disabled on Monday and Friday. I have the code written to return a day value as a number, then convert it to a day(name). The code I have been altering was disabling all input checkboxes onLoad that have a certain class applied to them, so I've been altering that to see if I can write an If/Else statement, but can't seem to get it right. Any ideas what I can change this to, so it will work?

var d = new Date();
var days = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
document.getElementById("demo").innerHTML = days[d.getDay()];

if days = 'Monday' {
    $('.sum').attr('disabled', true);
} else {
    $('.sum').attr('disabled', false);
}

<p style="margin: 20px;">Today is <span id="demo"></span>!</p>
<input style="margin: 20px 0 20px 20px;" value="50" type="checkbox" class="sum" data-toggle="checkbox" name="item"> Item 1 (Not availalbe Mondays/Fridays)

Thanks in advance for any insight!!




Aucun commentaire:

Enregistrer un commentaire