Click here to Skip to main content
15,917,795 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hear is my code given below--
<script type="text/javascript">
$(document).ready(function () {
$("#txtaddDateOfIssue").datepicker({
// maxDate: "-18Y"
dateFormat: 'dd/M/yy'
, changeMonth: true
, changeYear: true
});
BulkMethodCall();

var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(function () {
BulkMethodCall();

});

function BulkMethodCall() {
$('.googleJqueryDate').datepicker({
dateFormat: 'dd/M/yy'
, changeMonth: true
, changeYear: true
//, yearRange: "-50:+0"
, minDate: 0

, onSelect: function (date, inst) {
if (inst.id == "ctl00_content_txtaddDateOfReturn") {

if ($('#ctl00_content_txtaddDateOfIssue').val() == "") {
$('#ctl00_content_txtaddDateOfReturn').val("");
alert('Please Choose From Date First!');
}
else {
var StartDate = $('#ctl00_content_txtaddDateOfIssue').val();
var EndDate = $('#ctl00_content_txtaddDateOfReturn').val();

var dt1 = parseInt(StartDate.substring(0, 2), 10);
var mon1 = StartDate.substring(3, 6);
var yr1 = parseInt(StartDate.substring(7, 11), 10);
var StartdateNew = new Date(yr1, GetMonthValue(mon1) - 1, dt1);

var BTDate1 = parseInt(EndDate.substring(0, 2), 10);
var BTMon1 = EndDate.substring(3, 6);
var BTYear1 = parseInt(EndDate.substring(7, 11), 10);
var EndDateNew = new Date(BTYear1, GetMonthValue(BTMon1) - 1, BTDate1);

if (EndDateNew < StartdateNew) {
alert('Leave End Date can not be earlier than Leave Start Date!');
$(this).val("");
}
}
}
else {
$('#ctl00_content_txtaddDateOfReturn').val("");
}
}
});

function GetMonthValue(monthname) {
var monthvalue;
switch (monthname) {
case "Jan": monthvalue = 1; break;
case "Feb": monthvalue = 2; break;
case "Mar": monthvalue = 3; break;
case "Apr": monthvalue = 4; break;
case "May": monthvalue = 5; break;
case "Jun": monthvalue = 6; break;
case "Jul": monthvalue = 7; break;
case "Aug": monthvalue = 8; break;
case "Sep": monthvalue = 9; break;
case "Oct": monthvalue = 10; break;
case "Nov": monthvalue = 11; break;
case "Dec": monthvalue = 12; break;
}
return monthvalue;
}


$('.googleJqueryDate').attr("placeholder", "dd/MM/yyyy");
$('.googleJqueryDate').attr("onkeyup", "return false;");
$('.googleJqueryDate').attr("onkeydown", "return false;");
$('.googleJqueryDate').attr("onPaste", "return false;");


}
});
</script>

What I have tried:

i want to try when i click one text and select daten then if i click next text then it will show you cant select minimum date

please help me
Posted
Updated 5-Mar-16 1:44am

1 solution

Use code to manipulate the behaviors of the todate and fromdate datepickers as follows:
1. Enable the todate datepicker only when there is a selected date in the fromdate datepicker.
2. Set the min date for the todate datepicker to the selected date of the fromdate datepicker.
For example:
  <script>
  $(function() {
    
    var $from = $("#from");
    var $to = $("#to");

    $to.datepicker({disabled:true});
					   
    $from.datepicker({
      onClose: function( selectedDate ) {
          $to.datepicker( "option", "disabled", selectedDate == "" );
	  $to.val(selectedDate);
	  $to.datepicker( "option", "minDate", selectedDate );
      }
    });
    $to.datepicker({
      onClose: function( selectedDate ) {
        $from.datepicker( "option", "maxDate", selectedDate );
      }
    });
  });
  </script>
</head>
<body>
 
<label for="from">From</label>
<input type="text" id="from" name="from">
<label for="to">to</label>
<input type="text" id="to" name="to">
 
 
</body>
 
Share this answer
 
v2

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