Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 514101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:29:23+00:00 2026-05-13T07:29:23+00:00

I am currently using jquery ui datepicker for forms that have date inputs. The

  • 0

I am currently using jquery ui datepicker for forms that have date inputs. The problem is on my current form I need the user to just select a month. How would I got about doing this using jquery ui date picker?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T07:29:24+00:00Added an answer on May 13, 2026 at 7:29 am

    You could take advantage of the configurability of jQuery UI’s datepicker and use some CSS and JavaScript to achieve the behavior you’ve described. The following solution uses CSS to hide the calendar portion of the datepicker and some JavaScript to handle the month and year selection:

    Working Demo

    http://jsbin.com/uzafo (editable via http://jsbin.com/uzafo/edit)

    Full Source

    monthAndYear.css

    .ui-datepicker.monthAndYear {
      width: 20em;
    }
    .ui-datepicker.monthAndYear .ui-datepicker-calendar {
      display: none;
    }
    .ui-datepicker.monthAndYear .ui-datepicker-header {
      margin-bottom: 0.2em;
    }
    

    monthAndYear.js

    var monthAndYear = {
      /**
       * datepicker doesn't update the input field since
       * we don't actually select a date, so we have to 
       * manually determine the selected month and year
       * and update the input field ourselves.
      **/
      getMonthAndYear: function (dateText, instance) {
        if (!instance.settings.monthAndYear) {
          return;
        }
    
        var
          selectedYear = instance.selectedYear,
          selectedMonth = instance.selectedMonth,
          selectedDate = new Date(selectedYear, selectedMonth),
          dateFormat = 
            instance.settings.originalDateFormat ||
            instance.settings.dateFormat ||
            $.datepicker.regional[''].dateFormat;
    
        $(this).val($.datepicker.formatDate(dateFormat, selectedDate));
      },
    
      /**
       * If we want to use normal datepickers on the same page
       * we have to add and remove the modified styles accordingly
      **/
      styleMonthAndYear: function (input, instance) {
        var
          dpDiv = instance.dpDiv,
          className = 'monthAndYear';
        if (instance.settings.monthAndYear) {
          dpDiv.addClass(className);
        }
        else {
          dpDiv.removeClass(className);
        }
      }
    }
    

    main.js

    $.datepicker.setDefaults({
      beforeShow: monthAndYear.styleMonthAndYear,
      onClose: monthAndYear.getMonthAndYear
    });
    
    $(function () {
      $('#vanillaDatePicker').datepicker();
    
      $('#modifiedDatepickerOne').datepicker({
        monthAndYear: true
      });
    
      $('#modifiedDatepickerTwo').datepicker({
        monthAndYear: true,
        changeYear: true
      });
    
      /**
       * We have to do a bit of trickery here, in order to use a
       * dateFormat ('yy-mm') that datepicker normally wouldn't accept.
       * We parse the date manually and clear the dateFormat setting
       * in order to force datepicker to use the defaultDate setting.
       * We also save the original dateFormat so that we can
       * use it later in getMonthAndYear.
      **/
      $('#modifiedDatepickerThree').datepicker({
        monthAndYear: true,
        changeYear: true,
        dateFormat: 'yy-mm',
        beforeShow: function (input, instance) {
          monthAndYear.styleMonthAndYear.call(this, input, instance);
    
          var 
            date = $.datepicker.parseDate('yy-mm-dd', input.value + '-01'),
            originalDateFormat =
              instance.settings.dateFormat ||
              instance.settings.originalDateFormat;
    
          return {
            originalDateFormat: originalDateFormat,
            dateFormat: '',
            defaultDate: date
          };
        }
      });
    });
    

    main.html

    <!doctype html>
    <html lang="en">
      <head>
        <title>jQuery UI datepicker Month and Year Modification</title>
        <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
        <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/base/jquery-ui.css" type="text/css" />
        <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js" type="text/javascript"></script>
    
        <link rel="stylesheet" href="monthAndYear.css" type="text/css" />
        <script src="monthAndYear.js" type="text/javascript"></script>
    
        <script src="main.js" type="text/javascript"></script>
      </head>
      <body>
        <h1>jQuery UI datepicker Month and Year Modification</h1>
    
        <h2>Vanilla datepicker</h2>
        <input type="text" id="vanillaDatePicker" value="03/20/2009" />
    
        <h2>Modified datepicker</h2>
        <input type="text" id="modifiedDatepickerOne" value="03/20/2009" />
    
        <h2>Modified datepicker with a dropdown to change the year</h2>
        <input type="text" id="modifiedDatepickerTwo" value="03/20/2009" />
    
        <h2>Modified datepicker with custom date format</h2>
        <input type="text" id="modifiedDatepickerThree" value="2009-03" />
      </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 377k
  • Answers 377k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can call InvokeRequired on any WinForms Control-derived type to… May 14, 2026 at 8:45 pm
  • Editorial Team
    Editorial Team added an answer Static method calls are resolved on compile time (no dynamic… May 14, 2026 at 8:45 pm
  • Editorial Team
    Editorial Team added an answer Apparently if you are using the aplha version it will… May 14, 2026 at 8:45 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.