Javascript DOM HTML Input Week required Property get

Introduction

Find out if a week field must be filled out before submitting a form:

var x = document.getElementById("myWeek").required;

input elements with type="week" are not supported in Internet Explorer or Firefox.

View in separate window

<!DOCTYPE html>
<html>
<body>

<form action="/action_page.php">
  Week: <input type="week" id="myWeek" name="week_year" required>
  <input type="submit">
</form>/*from  w w w  . j  a  v  a  2s. c o  m*/
<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 required property sets or gets whether a week field must be filled out before submitting a form.

This property mirrors the HTML required attribute.

The <input type="week"> element is not supported in Firefox.

Property Values

Value Description
trueThe week field is a required part of form submission
false Default. The week field is not a required part of form submission

The required property returns true if the week field is a required part of form submission, otherwise it returns false.




PreviousNext

Related