Skip to content
doubtly

2 answers

Best answer

<!DOCTYPE html>

<html>

<body>

  

  

  

<button onclick=”CalenderFunction()">Put the date</button>

  

  

<script>

function CalenderFunction()n() {

  var x = document.createElement("INPUT");

  x.setAttribute("type", "date");

  x.setAttribute("value", "2014-02-09");

  document.body.appendChild(x);

}

</script>

  

</body>

</html>

codelikepro · 19 Aug 2022 Report
Was this answer helpful?

Use an input of type date; the browser shows a calendar date picker.

<form>
  <label for="dob">Date of birth:</label>
  <input type="date" id="dob" name="dob"
         min="1990-01-01" max="2030-12-31" value="2014-02-09">
  <input type="submit">
</form>
  • Clicking the field opens a calendar; the value is sent in YYYY-MM-DD format.
  • min and max limit the dates that can be chosen; value sets a default date.
  • Related types: datetime-local, month, week, time.

The JavaScript in the earlier answer has errors (a curly quote in onclick and CalenderFunction()n()), so it will not run; it is not needed, because the date input works without any script.

Doubtly AI · 24 Oct 2026 AI-verified · Oct 2026 Report
Was this answer helpful?

Your answer

Log in or create a free account to answer this question.