none
JQuery datepicker RRS feed

  • Question

  • Hi, 

    Am using JQuery Datepicker in that i am selecting only Month and year and am getting the value and assigning the value to a text box if i want to select another month or year the value in text box is resetting to the default drop down value. am unable to maintain the selected value in dropdown's . can any one suggest how to main it.

    This is my Code

    script files:-

    <script src="../SiteAssets/MedcomJs/Custom jq-ui.js" type="text/javascript"></script>

    <script src="../SiteAssets/MedcomJs/jQueryv1.11.1.js" type="text/javascript"></script>
    <link href="../SiteAssets/MedcomCss/Jquery-ui.css" rel="stylesheet" type="text/css"/> 

    HTML:-

    <div class="dpicker">
         <input name="startDate" id="SCAactionmonthss" class=" date-picker formdatepicker"  /> 
    </div>

    Script:-

         $( "#SCAactionmonthss" ).next().bind("click",function () {
        $(".ui-datepicker-calendar,.ui-datepicker-next,.ui-datepicker-prev").css("display","none");
        var month=  $(".ui-datepicker-month").find('option:selected').text();
      var year=  $(".ui-datepicker-year").find('option:selected').text();
            $("#SCAactionmonthss").val(month+" "+year);
        });
        
        $(document).on("keyup keypress focus", $( "#SCAactionmonthss" ).next(), function(e) {
        if(e.which==9){
        $(".ui-datepicker-calendar,.ui-datepicker-next,.ui-datepicker-prev").css("display","none");}
        });

        $(function() {
        $('.date-picker').datepicker( {
            showOn: "button",
            buttonImage: "/_layouts/15/images/calendar_25.gif",
            buttonImageOnly: true,
            //buttonText: "Select Month",
            changeMonth: true,
            changeYear: true,
            dateFormat: 'M yy',
            minDate: new Date(),
            onSelect: function(dateText, inst) {
            $(".date-picker").datepicker("option", "defaultDate", dateText);
        },
            }).focus(function() {
      $(".ui-datepicker-calendar,.ui-datepicker-prev, .ui-datepicker-next").remove();
      var month=  $(".ui-datepicker-month").find('option:selected').text();
      var year=  $(".ui-datepicker-year").find('option:selected').text();
                $("#SCAactionmonthss").val(month+" "+year);
          });
          
    });


    Bhavya Sruthi

    Wednesday, September 20, 2017 8:47 AM