Pages

Friday, September 6, 2013

Jquery datepicker with month and year only


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml" xml:lang="en">
<head><title>
 Home Page
</title><link href="Styles/Site.css" rel="stylesheet" type="text/css" />
</head>
<body>
<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">
        $(document).ready(
    function () {
        $('#txtPeriod').datepicker(
        {
            changeMonth: true,
            changeYear: true,
            dateFormat: 'MM yy',
            onClose: function () {
                var iMonth = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
                var iYear = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
                $(this).datepicker('setDate', new Date(iYear, iMonth, 1));
            },
            beforeShow: function () {
                if ((selDate = $(this).val()).length > 0) {
                    iYear = selDate.substring(selDate.length - 4, selDate.length);
                    iMonth = jQuery.inArray(selDate.substring(0, selDate.length - 5), $(this).datepicker('option', 'monthNames'));
                    $(this).datepicker('option', 'defaultDate', new Date(iYear, iMonth, 1));
                    $(this).datepicker('setDate', new Date(iYear, iMonth, 1));
                }
            }
        });
    });
</script>
<style>
        .ui-datepicker-calendar
        {
            display: none;
        }
        .red
        {
            color: Red;
            font-size: 10px;
        }
       
        td
        {
            text-align: left;
        }
        #divValidate
        {
            text-align: center;
        }
    </style>
<div id="divPeriod" style="display: none;">
 Period :
 <asp:TextBox ID="txtPeriod" runat="server" Width="100px" onkeydown="return false;"></asp:TextBox>
</div>
</body>
</html>

No comments:

Post a Comment