Click here to Skip to main content
15,915,660 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi.

I have two input text like
HTML
<input id="txtDT1" type="text" class="pdate" />
<input id="txtDT2" type="text" class="pdate" />


I am using datepicker on both of them.

eg

JavaScript
$('#txtDT1').datepicker({
            minDate: 0, changeMonth: true, changeYear: true, dateFormat: "mm/dd/yy"
        });


$('#txtDT2').datepicker({
            minDate: 0, changeMonth: true, changeYear: true, dateFormat: "mm/dd/yy"
        });


Now the problem is that in txtDT2, I have to set minDate property as selected on txtDT1. Please help.
Posted

1 solution

Try this:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script></script>
 <script>
$(document).ready(function(){
    $( "#datepicker1" ).datepicker({         
        onClose: function() {
            var date2 = $('#datepicker1').datepicker('getDate'); 
            $( "#datepicker2").datepicker("setDate", date2).datepicker('option', 'minDate', date2);
        }
    });
    $( "#datepicker2" ).datepicker();
});
</script>
</head>
<body>
<p>Date1: <input type="text" id="datepicker1"></p>
<p>Date2: <input type="text" id="datepicker2"></p>
</body>
</html>
 
Share this answer
 
Comments
ujju.1 4-Aug-14 5:27am    
Thanx Peter. Its working fine.
But what if there are 5-10 datepickers (created dynamically)? How can i use it through loop?

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