Input Text size Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Text

Description

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.

Return Value

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:

Demo Code

ResultView the demo in separate window

<!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>

Related Tutorials