Input URL defaultValue Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input URL

Description

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

The default value is the value specified in the HTML value attribute.

You can use defaultValue property to find out whether the URL of a URL field have been changed.

Set the defaultValue property with the following Values

Value Description
value Sets the default value of the URL field

Return Value

A String, representing the default value of the URL field

The following code shows how to change the default value of a URL field:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>
Homepage: <input type="url" id="myURL" value="http://www.google.com">

<button type="button" onclick="myFunction()">Test</button>

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

<script>
function myFunction() {//  w ww  .  j  a  va  2  s.  c  om
    var x = document.getElementById("myURL");
    x.defaultValue = 'new value';

}
</script>

</body>
</html>

Related Tutorials