Input Datetime required Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Datetime


The required property sets or gets whether a datetime field must be filled before submitting a form.

This property reflects the HTML required attribute.

Set the required property with the following Values

Value Description
true|false Sets whether a datetime field should be a required part of form submission.
  • true - The datetime field is a required
  • false - Default. The datetime field is not a required

Return Value

A Boolean, returns true if the datetime field is a required part of form submission, otherwise it returns false

The following code shows how to check if a datetime field must be filled out before submitting a form:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<form action="#">
  Date: <input type="datetime" id="myDatetime" name="date">
  <input type="submit">
</form>//from w w w  .  ja v  a2 s .  c  om

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

function myFunction() {
    var v = document.getElementById("myDatetime").required;
    document.getElementById("demo").innerHTML = v;

Related Tutorials