Javascript Reference - HTML DOM Input URL size Property








The size attribute specifies the width of an URL field in number of characters. The default value is 20.

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

Browser Support

size Yes 10.0 Yes Yes Yes

Syntax

Return the size property.

var v  = urlObject.size

Set the size property.

urlObject.size=number




Property Values

Value Description
number Set the width of the URL field, in number of characters. Default value is 20

Return Value

A Number type value representing the width of the URL field, in number of characters.

Example

The following code shows how to get the width of a URL field in number of characters.


<!DOCTYPE html>
<html>
<body>
<!-- ww  w  .  j  a  va  2s  .co m-->
Homepage: <input type="url" id="myURL" size="30">
<button onclick="myFunction()">test</button>
<p id="demo"></p>

<script>
function myFunction() {
    var x = document.getElementById("myURL").size;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to change the width of a URL field.


<!DOCTYPE html>
<html>
<body>
<!--from   w w w. j  a v  a2s . co  m-->
Homepage: <input type="url" id="myURL">
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
    document.getElementById("myURL").size = "50";
}
</script>

</body>
</html>

The code above is rendered as follows: