Input Text defaultValue Attribute

Definition and usage

defaultValue Sets or returns the default value of a text field.

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

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 whether the content of the text field has changed.

Example

Example 1

Change the default value of a text field:

document.getElementById("myText").defaultValue = "Steve";

Try it yourself

Example 2

Get the default value of a text field:

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

Try it yourself

Example 3

Example to show the difference between defaultValue and value properties:

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

Try it yourself

Syntax

Return the defaultValue property:

textObject.defaultValue

Set defaultValue property:

textObject.defaultValue = value

Attribute Value

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

Technical Details

Return Value: A string value representing the default value of the text field.

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support Support Support Support Support