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