Javascript DOM HTML Input Email required Property set

Introduction

Set an email field to be a required part of form submission:

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

Click the "Test" button to set the required property for the email field.

View in separate window

<!DOCTYPE html>
<html>
<body>

<form action="/action_page.php">
  E-mail: <input type="email" id="myEmail" name="usremail">
  <input type="submit">
</form>//from   w w w.  j a  v a2  s  .  c  om
<button onclick="myFunction()">Test</button>

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

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

</body>
</html>



PreviousNext

Related