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