Javascript examples for DOM HTML Element:Input Text
The size property sets or gets the size attribute of a text field, which sets the width of a text field (in number of characters).
The default value is 20.
Set the size property with the following Values
Value | Description |
---|---|
number | Sets the width of the text field, in characters. |
A Number, representing the width of the text field, in number of characters
The following code shows how to Set the width of a text field:
<!DOCTYPE html> <html> <body> Name: <input type="text" id="myText"> <button onclick="myFunction()">Test</button> <script> function myFunction() {/*from w w w. j a v a 2 s . com*/ document.getElementById("myText").size = "50"; } </script> </body> </html>