Specify only YEAR and MONTH for input date min/max attributes
html, input, javascript
Solution
You could use something like this:
<input class="month-date" type="date" max="2014-02">
var els = document.getElementsByClassName("month-date");
for(var i=0, l=els.length; i<l; ++i) {
var max = els[i].getAttribute('max').split('-');
max.push(new Date(max[0], max[1], 0).getDate());
els[i].max = max.join('-');
}
Demo
Problem
i have the following: ``` <input type="date" max="2014-10-31"> ``` Can i specify only the year and the month? I guess it'd be like: ``` <input type="date" max="2014-10-xx"> ``` or just ``` <input type="date" max="2014-10"> ``` (assuming the format is yyyy/mm/dd). And HTML does the rest. I can't specific the day, only year and month (given by server-side), because there are different max days for each month (like february, which has 28). So, can not be 31 the max. when i put 31 [day] for max attribute, the months that have 28, 30 stop working, i mean, the `input` gets weird and so i can modify the month too, but it can't happen cause the user should be able only to change the day - the month and the days are specific.