3

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.

7
  • u don't want to show any dates..?? Commented Dec 31, 2014 at 8:20
  • Am i get you correct that you want only specific dates it your data picker? Commented 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. Commented Dec 31, 2014 at 8:55
  • jsfiddle.net/b0efyzcc/4 Commented 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/5 Commented Dec 31, 2014 at 11:16

2 Answers 2

3

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"/>

Sign up to request clarification or add additional context in comments.

7 Comments

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.
For example : dateFormat: 'Nov 2014'
When you select date then it will show the same format like 'Nov 2014'.
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.
In resultant I'll get 3 months calendar on the page, Jan 2014, Feb 2014 and Mar 2014.
|
2

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});

    }

})();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.