multiple instances of a datepicker on single input

multiple instances of a datepicker on single input

I have a drop down(asp.net) with list items "month" & "day"..and i have a text box control and a datepicker..
 if i select "month" then i should be able get a datepicker with only month & year displayed and if i select day then day month & year as a normal date picker..i have this following code but the problem with this is a single input not able hold two instances of datepicker..any help is very much appreciated !! thanks in advance.


  1. <script type="text/javascript">
  2.         
  3.         function formatondropdownchange(value) {
  4.             if (value == "2") {
  5.                 $("#datepicker1").datepicker({
  6.                     showOn: "button",
  7.                     buttonImage: "calender.png",
  8.                     buttonImageOnly: true,
  9.                     minDate: "-3M",
  10.                     maxDate: "0",
  11.                     changeMonth: true,
  12.                     changeYear: true,
  13.                     dateFormat: 'MM yy',
  14.                     showButtonPanel: true,
  15.                     onClose: function (dateText, inst) {
  16.                         var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
  17.                         var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
  18.                         $(this).datepicker('setDate', new Date(year, month, 1));
  19.                     },
  20.                     beforeShow: function (input, inst) {
  21.                         if ((datestr = $(this).val()).length > 0) {
  22.                             year = datestr.substring(datestr.length - 4, datestr.length);
  23.                             month = jQuery.inArray(datestr.substring(0, datestr.length - 5), $(this).datepicker('option', 'monthNames'));
  24.                             $(this).datepicker('option', 'defaultDate', new Date(year, month, 1));
  25.                             $(this).datepicker('setDate', new Date(year, month, 1));
  26.                         }
  27.                     }
  28.                 })
  29.                 $("#datepicker1").focus(function () {
  30.                     $(".ui-datepicker-calendar").hide();
  31.                     $("#ui-datepicker-div").position({
  32.                         my: "center top",
  33.                         at: "center bottom",
  34.                         of: $(this)
  35.                     })
  36.                 })

  37.             }
  38.             else if (value == "3") {
  39.                 $("#datepicker1").datepicker({
  40.                     showOn: "button",
  41.                     buttonImage: "calender.png",
  42.                     buttonImageOnly: true,
  43.                     minDate: "-20",
  44.                     maxDate: "0",
  45.                     dateFormat: 'yy-MM-dd'

  46.                 })
  47.             }
  48.         }
  49.     </script>

  50. <input type="text" id="datepicker1"  />
  51.  <asp:DropDownList runat="server" ID="ddlInterval" Height="20px" Width="125px" AutoPostBack="false"
  52.             ClientIDMode="static" onChange="formatondropdownchange(this.value)" >
  53.             <asp:ListItem Text="select" Value="select" />
  54.             <asp:ListItem Text="Month" Value="2" />
  55.             <asp:ListItem Text="Day" Value="3" />
  56.             <asp:ListItem Text="Hour" Value="4" />
  57.         </asp:DropDownList>