onchange on date inputs

21,553

You could store the value in a global and check for a difference onclick.

<input type="date" name="myDate" id="myDate" />

var myApp = {};
myApp.myDate = "";

document.getElementById('myDate').onclick = function (e) {
    if (this.value != myApp.myDate) {
        // run onchange code

        // then set last value to current value
        myApp.myDate = this.value;
    }
};

See example →

EDIT: Or, duplicate question, like comments suggest. (See oninput event)

Share:
21,553
tbleckert
Author by

tbleckert

Silence is everything...

Updated on December 08, 2020

Comments

  • tbleckert
    tbleckert over 3 years

    Possible Duplicate:
    What events does an <input type=“number” /> fire when it's value is changed?

    I have a date input field

    <input type="date" name="..">
    

    In webkit and firefox, it will be added two up/down arrows on the side of the input. When clicking them, the date goes forward or backwards, but the onchange event doesn't trigger until the field loses focus. Is there a workaround for this?