The required
property sets or gets whether a
datetime field must be filled before submitting a form.
required |
No | No | No | No | No |
Return the required property.
var v = datetimeObject.required
Set the required property.
datetimeObject.required=true|false
Value | Description |
---|---|
true|false | Set whether a datetime field is a required part of form.
|
A Boolean type value, true if the datetime field is a required part of form submission, otherwise false.
The following code shows how to set a datetime field to be required.
<!DOCTYPE html>
<html>
<body>
<!-- www .j a v a 2s .c om-->
<form action="url">
Date: <input type="datetime" id="myDatetime" name="date">
<input type="submit">
</form>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
document.getElementById("myDatetime").required = true;
document.getElementById("demo").innerHTML = "changed";
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to get if a datetime field must be filled out before submitting a form.
<!DOCTYPE html>
<html>
<body>
<!-- w w w .ja va 2s. c o m-->
<form action="url">
Date: <input type="datetime" id="myDatetime" name="date" required>
<input type="submit">
</form>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myDatetime").required;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows: