Input Week required Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Week

Description

The required property sets or gets whether a week field must be filled out before submitting a form.

This property reflects the HTML required attribute.

Set the required property with the following Values

Value Description
true|false Sets whether a week field should be a required part of form submission.

Return Value

A Boolean, returns true if the week field is a required part of form submission, otherwise it returns false

The following code shows how to check if a week field must be filled out before submitting a form:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<form action="#">
  Week: <input type="week" id="myWeek" name="week_year">
  <input type="submit">
</form>//  www. ja v  a  2  s .c om

<button onclick="myFunction()">Test</button>

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

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

</body>
</html>

Related Tutorials