Is it possible to show a jquery inline datepicker by a specific month and year? Lets say I want to see the inline datepicker for Nov 2014. And it shows the complete month without selecting any date.
-
u don't want to show any dates..??Nibin– Nibin2014-12-31 08:20:58 +00:00Commented Dec 31, 2014 at 8:20
-
Am i get you correct that you want only specific dates it your data picker?teo van kot– teo van kot2014-12-31 08:21:50 +00:00Commented Dec 31, 2014 at 8:21
-
@Learner I want simple datepicker. The only thing that I want is just it goes to a specific month. Nothing else. I'll setDate later on using the method.Superman– Superman2014-12-31 08:55:22 +00:00Commented Dec 31, 2014 at 8:55
-
jsfiddle.net/b0efyzcc/4Umesh Sehta– Umesh Sehta2014-12-31 10:36:58 +00:00Commented Dec 31, 2014 at 10:36
-
@Learner Can you take a look over this fiddle? This is the only code we need to get it work. But unfortunately it isn't working. jsfiddle.net/Superman/b0efyzcc/5Superman– Superman2014-12-31 11:16:16 +00:00Commented Dec 31, 2014 at 11:16
|
Show 2 more comments
2 Answers
Try to use option-dateFormat like,
$(function() {
$( "#datepicker" ).datepicker({
dateFormat: 'M yy'
});
});
$(function() {
$( "#datepicker" ).datepicker({
dateFormat: 'M yy'
});
});
<link href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<input id="datepicker"/>
If you want to showonly month and year drop down then try the below snippet
$(function() {
$( "#datepicker" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat: 'M yy',
});
});
<link href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<input id="datepicker"/>
7 Comments
Superman
Rohan The way first datepicker selects the date which is Only month and year. I want to specify it the same way before getting it instantiated or rendered on html page.
Superman
For example : dateFormat: 'Nov 2014'
Rohan Kumar
When you select date then it will show the same format like 'Nov 2014'.
Superman
I have an array of months like this which contains [Jan 2014, Feb 2014, Mar 2014 ...] and before creating the datepicker. I want to provide this array to create an inline datepicker for each month.
Superman
In resultant I'll get 3 months calendar on the page, Jan 2014, Feb 2014 and Mar 2014.
|
Not only One. You can even create multiple instances of datepicker each of them will be of different month. Look here.
(function(){
for( var i=0; i<5; i++ ){
var dateObj = new Date();
dateObj.setMonth(i);
dateObj.setYear(dateObj.getFullYear());
var dp = $('<div id="calendar' + i + '" > </div>');
$('#Calendar').append(dp);
console.log("Month: "+dateObj.getMonth());
dp.datepicker({defaultDate: dateObj});
}
})();