Javascript DOM HTML Input Datetime required Property set

Introduction

Set a datetime field to be a required part of form submission:

document.getElementById("myDatetime").required = true;

Click button to set the required property for the datetime field.

View in separate window

<!DOCTYPE html>
<html>
<body>

<form action="/action_page.php">
  Date: <input type="datetime" id="myDatetime" name="date">
  <input type="submit">
</form>//  w w w  . j  a v a 2 s  .c  o  m
<button onclick="myFunction()">Test</button>
<p id="demo"></p>

<script>
function myFunction() {
  document.getElementById("myDatetime").required = true;
  document.getElementById("demo").innerHTML = "The required property was set.";
}
</script>

</body>
</html>



PreviousNext

Related