Javascript DOM HTML Input Time required Property set

Introduction

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

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

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

View in separate window

<!DOCTYPE html>
<html>
<body>

<form action="/action_page.php">
  Time: <input type="time" id="myTime" name="usr_time">
  <input type="submit">
</form>//from   w w  w.j  av  a2  s  .c  o  m
<button onclick="myFunction()">Test</button>

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

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

</body>
</html>



PreviousNext

Related