I am using this bootstrap datepicker http://www.eyecon.ro/bootstrap-datepicker/:
<script type="text/javascript">
var dateToday = new Date();
$(function() {
$("#id_deadline").datepicker({minDate: dateToday});
});
</script>
I want to let select the date from today to future only (not a past date). Datepicker is showing up and it is letting me select the past date too. What's wrong?
Because you're defining the code in the head the body and its contents haven't been loaded yet; so the selector finds no elements to initialize datepicker. If you don't want to use document. ready functionality you could also move the script to the end of the body tag.
For most datepickers, simply set data-provide="datepicker" on the element you want to initialize, and it will be intialized lazily, in true bootstrap fashion. For inline datepickers, use data-provide="datepicker-inline" ; these will be immediately initialized on page load, and cannot be lazily loaded.
ready(function () { $('#date'). datetimepicker({ //defaultDate: new Date() //date-disabled="now" //default: false }); }); bootstrap-datetimepicker.
try using startDate
with this way :
$("#id_deadline").datepicker({startDate: new Date()});
I hope it will help you
try,
var dateToday = new Date();
$(function () {
$( "#datepicker1" ).datepicker({
format: 'yyyy-mm-dd',
autoclose: true,
startDate: dateToday
});
});
Backdate
var last7Days = new Date();
last7Days.setDate(last7Days.getDate()-7);
$(function () {
$( "#datepicker1" ).datepicker({
format: 'yyyy-mm-dd',
autoclose: true,
startDate: last7Days
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With