Javascript DOM HTML Input DatetimeLocal required Property

Introduction

Find out if a local datetime field is a required field in a form:

var x = document.getElementById("myLocalDate").required;
<p>Click button to find out if the local datetime field is a required field in the form.

View in separate window

<!DOCTYPE html>
<html>
<body>

<form action="/action_page.php">
  Date: <input type="datetime-local" id="myLocalDate" name="date" required>
  <input type="submit">
</form>/*from   www  . j ava 2 s.  co m*/
<button onclick="myFunction()">Test</button>
<p id="demo"></p>

<script>
function myFunction() {
  var x = document.getElementById("myLocalDate").required;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The required property sets or gets whether a local datetime field is a required field in a form.

This property mirrors the HTML required attribute.

The required property accepts and returns a boolean value.

Value Description
true The local datetime field is a required part of form submission
false Default. The local datetime field is not a required part of form submission

The required property returns true if the local datetime field is a required part of form submission, otherwise it returns false.




PreviousNext

Related