Javascript DOM HTML Input Text size Property set

Introduction

Set the width of a text field:

document.getElementById("myText").size = "50";

Click the button to set the width of the text field.

View in separate window

<!DOCTYPE html>
<html>
<body>

Name: <input type="text" id="myText">
<button onclick="myFunction()">Test</button>

<script>
function myFunction() {/*from   www. j  a v a  2  s . c  om*/
  document.getElementById("myText").size = "50";
}
</script>

</body>
</html>

The size property sets or gets the size attribute of a text field.

The size sets the width of a text field in number of characters.

The default value is 20.

The size property returns a Number representing the width of the text field, in number of characters.




PreviousNext

Related