help me please! I just can't do this: I have two calendars. in the first, the minimum date is today. then the user chooses any day. and in the second you need to set the minimum date to the one that the user selected in the first calendar. I will be grateful if you tell me how to do it

var now = new Date(); var today = now.getFullYear() + '-' + parseInt(now.getMonth() + 1) + '-' + now.getDate(); $(function() { $('.thisday').prop('min', function() { return new Date().toJSON().split('T')[0]; }); }); $(function() { $('.backDay').prop('min', function() { return //здесь должно быть то,чего я не знаю; }); }); 
 <input class="thisday" placeholder="date" type="date" id="min" max="2016-12-31"> <input class="backDay" placeholder="date" type="hidden" id="min" max="2016-12-31"> 

  • code in the studio, please - Blacknife
  • @Blacknife I already added - Oblivion
  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

1 answer 1

Each tag must have its own unique id , and you have two input tags, one id for two.

 var userCal=document.getElementById("min"); var shadowCal=document.getElementById("max"); userCal.addEventListener("change",function(e){ shadowCal.min=e.currentTarget.value; alert("Урра!!! Теперь атрибут min,тега input, класса backDay равен "+shadowCal.min); },false); 
 <input class="thisday" placeholder="date" type="date" id="min" max="2016-12-31"/> <input class="backDay" placeholder="date" type="date" id="max" max="2016-12-31"/> 

  • Well, I think we should add that some browsers (Mozilla Firefox, Safary, IE ...) have not yet made up for all the features of html5 and will not work in type="date" , therefore it is worth paying attention to an alternative solution in the form of a script , for example: jQueryUI Datepicker - Blacknife
  • I brought the demo code, I somehow didn’t work out with jquery - user205867
  • @ Otis666 thank you so much for the help! - Oblivion