Javascript DOM HTML Input Text size Property get

Introduction

Get the width of a text field:

var x = document.getElementById("myText").size;

Click the button to display the value of the size attribute in the text field.

View in separate window

<!DOCTYPE html>
<html>
<body>

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

<p id="demo"></p>

<script>
function myFunction() {//from  ww  w. j a va 2 s.co m
  var x = document.getElementById("myText").size;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related