Click here to Skip to main content
15,312,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm using jQuery date picker in my php site. It's working properly, but I want to disable previous date from it. I try to do in some ways but it's not working.

My script as follow

JavaScript
<link rel="stylesheet" type="text/css" media="all" href="<?php echo base_url("cal/jsDatePick_ltr.min.css"); ?>" />
<script type="text/javascript" src="<?php echo base_url("cal/jsDatePick.jquery.min.1.3.js"); ?>"></script>
<script type="text/javascript">
var today = new Date();
var y = today.getFullYear();
var m = today.getMonth();
var d=today.getDate();
window.onload = function() {
new JsDatePick({
useMode: 2,
target: "edate",
dateFormat: "%Y-%m-%d",
yearsRange:[y,9999]
});
};
</script>


My form as follow. I'm using codeigniter in this project:
PHP
<?php
$data = array(
"name" => "edate",
"id" => "edate",
"value" => "",
"class" => "form-control",
"placeholder" => "Expire Date",
"aria-describedby" => "sizing-addon1"
);
echo form_input($data);
?>


When I click on this texbox calender is popup successfully. but I want to disable previous dates from it.
Posted
Updated 25-Jul-18 21:52pm
Comments
FrankNight 12-Sep-15 17:17pm
   
If you use jQueryUI the bundled Datepicker Widget has a minDate option that is exactly what you want.

You can how disable previous dates from jQuery UI Datepicker like:

HTML:
HTML
<p>Date:<input type="text" id="datepicker"></p>


JS:
JavaScript
// Get today's date
var today = new Date();

$("#datepicker").datepicker({
    changeMonth: true,
    changeYear: true,
    minDate: today // set the minDate to the today's date
    // you can add other options here
});


DOCS:
- Datepicker[^]
- minDate [^]

/pm
   
v2
HTML Code
<p>Date: <input type="text" id="datepicker" /></p>

Javascript Code
$( "#datepicker" ).datepicker({ minDate: 0});
   
Comments
Richard Deeming 3-Jul-18 10:12am
   
THREE YEARS too late, and with code that doesn't even do what the question asked!
$(".dtpicker_date").datepicker({
autoclose: true,
format: 'dd-mm-yyyy',
startDate:'+0d',

});
   
Comments
CHill60 26-Jul-18 4:09am
   
Now here's a thing...the Datepicker Widget jQuery UI API Documentation[^] doesn't list any of those properties.
Richard Deeming 26-Jul-18 12:27pm
   
THREE YEARS too late, and with code that doesn't even work.

Stick to answering recent questions, and make sure you've read and understood the question and that your code works.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900