Javascript DOM HTML Input Search readOnly Property set

Introduction

Set a search field to read-only:

document.getElementById("mySearch").readOnly = true;

Click the button to set the search field to read-only.

View in separate window

<!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
falseDefault. The search field is not read-only

The readOnly property returns true if the search field is read-only, otherwise it returns false.




PreviousNext

Related