Javascript Reference - HTML DOM Input URL value Property








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

Browser Support

value Yes 10.0 Yes Yes Yes

Syntax

Return the value property.

var v = urlObject.value

Set the value property.

urlObject.value=URL

Property Values

Value Description
URL Get an absolute URL




Return Value

A String type value representing a URL.

Example

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


<!DOCTYPE html>
<html>
<body>
Homepage: <input type="url" id="myURL" value="http://www.google.com">
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<!--   w  w  w .j av a 2  s.co m-->
<script>
function myFunction() {
    document.getElementById("myURL").value = "http://www.cnn.com";
}
</script>

</body>
</html>

The code above is rendered as follows:





Example 2

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


<!DOCTYPE html>
<html>
<body>
Homepage: <input type="url" id="myURL" value="http://www.google.com">
<button onclick="myFunction()">test</button>
<!--from w  w w.  j a  v a  2 s.  c o  m-->
<p id="demo"></p>

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

</body>
</html>

The code above is rendered as follows: