javascript - How do I restrict past dates in html5 input type Date -
i trying restrict past dates in input type="date"
.i can able restrict future dates,but don't have idea restricting past dates.
$(function(){ var dttoday = new date(); var month = dttoday.getmonth() + 1; var day = dttoday.getdate(); var year = dttoday.getfullyear(); if(month < 10) month = '0' + month.tostring(); if(day < 10) day = '0' + day.tostring(); var mindate= year + '-' + month + '-' + day; $('#txtdate').attr('min', mindate); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="date" id="txtdate" />
any suggestion?
you can try this
var maxdate = year + '-' + month + '-' + day; alert(maxdate); $('#txtdate').attr('min', maxdate);
$(function(){ var dttoday = new date(); var month = dttoday.getmonth() + 1; var day = dttoday.getdate(); var year = dttoday.getfullyear(); if(month < 10) month = '0' + month.tostring(); if(day < 10) day = '0' + day.tostring(); var maxdate = year + '-' + month + '-' + day; alert(maxdate); $('#txtdate').attr('min', maxdate); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="date" id="txtdate" />
Comments
Post a Comment