2
votes

How to replace Jul, Jan, Feb, Mar, Apr, May, Jun, Aug, Sep, Oct, Nov, Dec with word: "Period 1, Period 2, Period 3, Period 4".

I think 'll make detail: - Make a array list - Add to Dropdownlist - Add to UI. but, i do'nt know how to make this

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.js"></script>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"></script>
    <link rel="stylesheet" type="text/css" media="screen" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/base/jquery-ui.css">
    <script type="text/javascript">
    $(function() {
        $('.date-picker').datepicker( {
            changeMonth: true,
            changeYear: true,
            showButtonPanel: true,
            dateFormat: 'MM yy',
            onClose: function(dateText, inst) { 
                var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
                var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
                $(this).datepicker('setDate', new Date(year, month, 1));
            },
            beforeShow : function(input, inst) {
                var datestr;
                if ((datestr = $(this).val()).length > 0) {
                    year = datestr.substring(datestr.length-4, datestr.length);
                    month = jQuery.inArray(datestr.substring(0, datestr.length-5), $(this).datepicker('option', 'monthNamesShort'));
                    $(this).datepicker('option', 'defaultDate', new Date(year, month, 1));
                    $(this).datepicker('setDate', new Date(year, month, 1));
                }
            }
        });
    });
    </script>
    <style>
    .ui-datepicker-calendar {
        display: none;
        }
    </style>
</head>
<body>
    <label for="startDate">Date :</label>
    <input name="startDate" id="startDate" class="date-picker" />
</body>
</html>

Thanks so much.

1

1 Answers

1
votes

This should do the trick (after initialization):

var monthNames = ['Period1','Period2','Period3','Period4','Period5','Period6',
    'Period7','Period8','Period9','Period10','Period11','Period12'];

var monthNamesShort = ['Per1', 'Per2', 'Per3', 'Per4', 'Per5', 'Per6',
    'Per7', 'Per8', 'Per9', 'Per10', 'Per11', 'Per12'];

$(".date-picker").datepicker( "option", "monthNames", monthNames);

$(".date-picker").datepicker( "option", "monthNamesShort", monthNamesShort);

Note that you should set monthNamesShort, too. These properties can also be set during initialization.

$(".date-picker").datepicker({
    ..., 
    monthNames: ['Period1', ...], 
    monthNamesShort:['Per1', ...],
    ...
});