Javascript DOM HTML Input URL size Property get

Introduction

Display the width of a URL field in number of characters:

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

Click the button to display the value of the size attribute of the URL field.

elements with type="url" are not supported in Safari.

View in separate window

<!DOCTYPE html>
<html>
<body>

Homepage: <input type="url" id="myURL" size="30">
<button onclick="myFunction()">Test</button>
<p id="demo"></p>

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

</body>
</html>



PreviousNext

Related