Change the text of a search field:
document.getElementById("mySearch").value = "Cars";
Click the button to change the value attribute of the search field.
<!DOCTYPE html> <html> <body> Search: <input type="search" id="mySearch" value="Food"> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {//ww w .ja v a 2 s . com document.getElementById("mySearch").value = "Cars"; } </script> </body> </html>
The value property sets or gets the value attribute of a search field.
The value attribute sets the default value OR the value a user types in.
The value property accepts and returns a String type value.