Display the width of a search field in number of characters:
var x = document.getElementById("mySearch").size;
Click the button to display the value of the size attribute of the search field.
<!DOCTYPE html> <html> <body> Search: <input type="search" id="mySearch" size="35"> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {//from w ww .java2 s.c o m var x = document.getElementById("mySearch").size; document.getElementById("demo").innerHTML = x; } </script> </body> </html>