Find out if a time field must be filled out before submitting a form:
var x = document.getElementById("myTime").required;
Click the "Test" button to find out if the time field is required.
<!DOCTYPE html> <html> <body> <form action="/action_page.php"> Time: <input type="time" id="myTime" name="usr_time" required> <input type="submit"> </form>/*from w w w.j av a 2 s. c om*/ <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() { var x = document.getElementById("myTime").required; document.getElementById("demo").innerHTML = x; } </script> </body> </html>
The required
property sets or gets whether a time field must be filled out before submitting a form.
This property mirrors the HTML required attribute.
The <input type="time"> element is not supported in Firefox.
The required
property accepts and returns a boolean type value.
Value | Description |
---|---|
true | The time field is a required part of form submission |
false | Default. The time field is not a required part of form submission |
The required
property returns true if the time field is a required part of form submission, otherwise it returns false.