Set a search field to read-only:
document.getElementById("mySearch").readOnly = true;
Click the button to set the search field to read-only.
<!DOCTYPE html> <html> <body> Search: <input type="search" id="mySearch"> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {//from w ww . j a v a 2s . c o m document.getElementById("mySearch").readOnly = true; } </script> </body> </html>
The readOnly property sets or gets whether a search field should be read-only.
A read-only field cannot be modified.
This property mirrors the HTML readonly attribute.
The readOnly property accepts and returns a boolean type value.
Value | Description |
---|---|
true | The search field is read-only |
false | Default. The search field is not read-only |
The readOnly property returns true if the search field is read-only, otherwise it returns false.