0

My HTML code

<div style="display: inline-block; font-weight: bold;">
    <label for="fromDateRange">From:</label>
    <div id="fromDateRange"></div>
</div>

<div style="margin-left:20px; display: inline-block; font-weight: bold;">
    <label for="toDateRange">Till:</label>
    <div id="toDateRange"></div>
</div>

My javascript:-

$('#toDateRange').datepicker({
    // minDate: $( "#fromDateRange" ).datepicker( "getDate" ),
    changeMonth: true,
    changeYear:true,
    numberOfMonths: 1,
    dateFormat: "yy-mm-dd", 
    onSelect: function( selectedDate ) {
        $( "#fromDateRange" ).datepicker( "option", "maxDate", selectedDate );
    }
});


$( "#fromDateRange").datepicker({
     defaultDate: "-1m",
     changeMonth: true,
     changeYear:true,
     numberOfMonths: 1,
     dateFormat: "yy-mm-dd",
     onSelect: function( selectedDate ) {
         $( "#toDateRange" ).datepicker( "option", "minDate", selectedDate );
    }
});

clear dates function:

function clearDates() {
    clear="";
    $('#dateFilter').val(clear);
    $("#dateFilter").trigger("change");
    $('#date-range').hide();        
}

Once I clear the active dates in the date picker should be the default one.How Do I do it?

Evgeniy
  • 2,915
  • 3
  • 21
  • 35
Shreyas
  • 23
  • 1
  • 1
  • 5

1 Answers1

0

If i got you right and you really want to set a date as default when the user uses clearDates() you have to store the Informations that was given.

For this you have to ways...

Way One (LocalStorage):

//set value to browser cache
    localStorage.setItem("key", "value");
//get from browser cache
    localStorage.getItem("key"); //returns the setted value
//remove specific entry from browser cache
    localStorage.removeItem("key"); //delete entry xy
//remove all from browser cache
    localStorage.clear();

Way two:

Use cookys.

Dwza
  • 6,494
  • 6
  • 41
  • 73