Input type time property required in Javascript
The Input type time property required used to set and retrieve whether the time field mandatory before submitting a form. It returns a boolean value true, if the time field should be fill before submitting form, otherwise false.
Syntax
 1 <input>.required // to retrieve
 2 <input>.required = <boolean> // to set
input : An input type required element object to set and retrieve required property
boolean : It specifies that the time input field should be mandatory or not

Possible values

1. true : It specifies that the time input field should be mandatory before submitting form2. false : It specifies that the time input field is optional, it is default, if not specified
Input time property required
 1 <!DOCTYPE html>
 2 <html>
 3 <style>
 4   .container {
 5     margin: 20px 0;
 6   }
 7 </style>
 8 <body>
 9 	<h1>The Input Time Object</h1>
 10 	<h2>Example</h2>
 11 	
 12 	<div class="container">
 13 	  <form>
 14 	    <input type="time" id="time" required />
 15 	    <input type="submit" />
 16 	  </form>
 17 	</div>
 18 	<div>
 19 	  <button onclick="mandatory(true)">Requird</button>
 20 	  <button onclick="mandatory(false)">Optional</button>
 21 	  <button onclick="access()">Access</button>	  
 22 	</div>
 23 		
 24 	<p id="result"></p>
 25 	<script>
 26 	function access() {
 27 	  const element = document.getElementById("time");
 28 	  const str = `Is time field is mandatory ? <b>${element.required}</b>`;
 29 	  document.getElementById("result").innerHTML = str;
 30 	}
 31 	function mandatory(value) {
 32 	  const element = document.getElementById("time");
 33 	  element.required = value;
 34 	}
 35 	</script>
 36 </body>
 37 </html>
Input time property required
Privacy Policy
Terms of Service
Disclaimer
Contact us
About us