Thursday, June 7, 2012

How to Disable previous Date in Jquery Datepicker.


<script type="text/javascript">
$(function() {
$("#txtStartDate").datepicker(
    {
    dateFormat: "dd/mm/yy",
        showOn: "button",
    changeYear: true,
    changeMonth: true,
    minDate:"0",
    onSelect:function()
    {
    UpdateStartDate();
    }
    }
    );
    $("#endValid").datepicker(
    {
    dateFormat: "dd/mm/yy",
    showOn: "button",
    changeYear: true,
    changeMonth: true,
    minDate:"0"
    }
    );
});


   
function UpdateStartDate()
{
str = $("#startValid").val();
if(str != "")
{
var parts = str.split("/");
parts[0]++;
date = new Date(parts[2], parts[1]-1, parts[0]);

$("#endValid" ).datepicker( "option", "minDate", date );
date2 = new Date();
date2.setFullYear(date.getFullYear(), date.getMonth(), date.getDate()-1);
date2.setMonth(date2.getMonth()+12, date2.getDate());

$( "#endValid" ).datepicker( "option", "default", date2 );
month = date2.getMonth()+1;
month = month.toString();
day = date2.getDate();
day = day.toString();
if(month.length == 1)
{
    month = "0" + month;
}
if(day.length == 1)
{
    day = "0" + day;
}
dateStr = day +"/"+month+"/"+date2.getFullYear();
if($("#endValid").val() == "")
  {
    $("#endValid").val(dateStr);
  }
 }
}
</script>

No comments:

Post a Comment