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