Search code examples
javascriptjquerydatepickeronblur

onblur taking last clicked value not taking current clicked value?


I am using onblur event to get the value of date in datepicker. Here is my control:

<input placeholder="MM/DAY/YEAR" data-bind="value: CustomerBookingTbl.PickUpDate" class="input date" name="pickupdate" onblur="UpdatePrice(this)" type="text" required>

and here is my function:

function UpdatePrice(_this)
{
    console.log(_this.value);
}

When I clicked on 06/07/2017 then it takes null. Afterward, I clicked on 06/07/2017 then it takes 06/06/2017 as a value.

I am attaching the image also console.log showing dates


Solution

  • Check out events provided by datePicker

    Datepicker triggers a number of events in certain circumstances. All events have extra data attached to the event object that is passed to any event handlers

    You could use this event to track changeDate event of date

    changeDate

    Fired when the date is changed.

    $("YOUR_DATE_PICKER").on("changeDate", function(e) {
        //// `e` here contains the extra attributes
        alert('hey');
    });
    

    Check this fiddle