Wednesday, 22 February 2012

jQuery Datepicker

Here’s a simple jQuery Datepicker example.

CODE:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<head>
<title>Ashish's blog -Datepicker</title>
</script>
</script>
<script type="text/javascript">
$(function () {
$("#date").datepicker();
});
</script>
</head>
<body>
<input id="date" type="text" />
</body>
</html>
In above example,date formate id mm/dd/yy but you change it to (‘dd-mm-yy’) by changing code:
1
2
3
4
5
6
7
8
<script type="text/javascript">
$(document).ready(function () {
$(function () {
//   $("#txtInvoiceDate").date_input();
$("#date").datepicker({ dateFormat: 'dd-mm-yy' });
});
});
</script>
OR prevent users from selecting weekends ..

1
2
3
4
5
6
7
<script type="text/javascript">
$(function () {
$("#datepic").datepicker({
beforeShowDay: $.datepicker.noWeekends
});
});
</script>
OR how to disable all the future dates….
1
2
3
4
5
6
7
8
9
10
11
12
13
<script type="text/javascript">
             $(function () {
 
                 var date = new Date();
                 var currentMonth = date.getMonth();
                 var currentDate = date.getDate();
                 var currentYear = date.getFullYear();
 
                 $("#datepic").datepicker({
                     maxDate: new Date(currentYear, currentMonth, currentDate)
                 });
             });
    </script>

No comments:

Post a Comment