The readOnly
property sets or gets
whether a search field should be read-only.
readOnly |
Yes | Yes | Yes | Yes | Yes |
Return the readOnly property.
var v = searchObject.readOnly
Set the readOnly property.
searchObject.readOnly=true|false
Value | Description |
---|---|
true|false | Set whether a search field should be read-only
|
A Boolean type value, true if the search field is read-only, otherwise false.
The following code shows how to get if a search field is read-only.
<!DOCTYPE html>
<html>
<body>
<!--from w w w. j a v a 2 s . c o m-->
Search: <input type="search" id="mySearch" readonly>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("mySearch").readOnly;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to set a search field to read-only.
<!DOCTYPE html>
<html>
<body>
<!--from www. java2 s . c om-->
Search: <input type="search" id="mySearch">
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
document.getElementById("mySearch").readOnly = true;
}
</script>
</body>
</html>
The code above is rendered as follows: