Skip to content Skip to sidebar Skip to footer

How To Make Data Input Readonly, But Showing Calendar?

I can't find any solution for this anywhere. I would like to allow user to see calendar when clicking on my input, but when user will try to change the value, it shouldn't change (

Solution 1:

You might try to set a time limit

<html>
<body>
<input type="date" value="2020-06-04">
<input type="date" value="2020-06-04" min="2020-06-04" max="2020-06-04">

</body>
</html>

Solution 2:

If I understood correctly, this is what you want.

HTML

<input class='test' type='date' value='2020-06-04' />

JavaScript

const date = "2020-06-04";
const input = document.querySelector('.test');

input.onkeydown = function(e) {
    return false;
}

input.onchange = function(e) {
    this.value = date;
}

Check out this JSFiddle

EDIT

function preventInputChange(input, staticValue) {
  input.onchange = function(e) {
    this.value = staticValue;
  }
}

Post a Comment for "How To Make Data Input Readonly, But Showing Calendar?"