The required
property sets or gets whether a
textarea must be filled before submitting a form.
required |
Yes | 10.0 | Yes | Yes | Yes |
Return the required property.
var v = textareaObject.required
Set the required property.
textareaObject.required=true|false
Value | Description |
---|---|
true|false | Set whether a textarea is required for form submission.
|
A Boolean type value, true if the textarea is a required part of form submission, otherwise false.
The following code shows how to check if a textarea must be filled before submitting a form.
<!DOCTYPE html>
<html>
<body>
<form action="url">
<textarea id="myTextarea" name="adr" required>this is a test</textarea>
</form><!--from ww w .j a v a 2 s.co m-->
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myTextarea").required;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to set a textarea to be a required part of form.
<!DOCTYPE html>
<html>
<body>
<form action="url">
<textarea id="myTextarea" name="adr"></textarea>
<input type="submit">
</form><!--from w w w . j a v a2s. co m-->
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
document.getElementById("myTextarea").required = true;
}
</script>
</body>
</html>
The code above is rendered as follows: