Javascript DOM HTML Input Week required Property set

Introduction

Set a week field to be a required part of form submission:

document.getElementById("myWeek").required = true;

Click the button to set the required property for the week field.

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">
  <input type="submit">
</form>// ww w  .  j  av  a 2s .c o  m
<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. The week field must now be filled out before submitting the form.";
}
</script>

</body>
</html>



PreviousNext

Related