Input URL defaultValue attribute

Definition and usage

defaultValue Sets or returns the default value of the URL field.

Note:The default value is HTML value attribute specified in.

The difference between defaultValue and value properties is that defaultValue contains the default value, while value contains the current value after some changes. If there is no change, defaultValue and value are the same (see the example below).

The defaultValue property is very useful if you want to check if the URL of the URL field has been changed.

Example

Example 1

Change the default value of the URL field:

document.getElementById("myURL").defaultValue = "https://www.ifeng.com";

Try it yourself

Example 2

Get the default value of the URL field:

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

Try it yourself

Example 3

Example to show the difference between defaultValue and value properties:

var x = document.getElementById("myURL");
var defaultVal = x.defaultValue;
var currentVal = x.value;

Try it yourself

Syntax

Return the defaultValue property:

urlObject.defaultValue

Set defaultValue Property:

urlObject.defaultValue = value

Attribute Value

Value Description
value Specifies the default value of the URL field.

Technical Details

Return Value: A string value that represents the default value of the URL field.

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Supported 10.0 Supported Not Supported Supported