
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
HTML DOM Input Text defaultValue Property
The HTML DOM Input Text defaultValue property is used for setting or getting the defaultValue of a text field. The defaultValue of an element is the value assigned to the value attribute. The difference between value property and defaultValue property is the latter retains the original default value specified while the value property value changes based on the user input in the input field.
Syntax
Following is the syntax to set the defaultValue property −
textObject.defaultValue = value
Here, “value” is the text field default value.
Example
Let us look at an example for the Text defaultValue property −
<!DOCTYPE html> <html> <body> <h1>Input Text defaultValue Property</h1> USERNAME: <input type="text" id="TEXT1" value="RON_1" autofocus> <p>Change the above text field default value by clicking on the CHANGE button</p> <button type="button" onclick="changeDefault()">CHANGE</button> <p id="Sample"></p> <script> function changeDefault() { document.getElementById("TEXT1").defaultValue="ROHAN_2"; var P=document.getElementById("TEXT1").defaultValue; document.getElementById("Sample").innerHTML = "Default value has been changed from RON_1 to "+P ; } </script> </body> </html>
Output
This will produce the following output −
- Related Articles
- HTML DOM Input Month defaultValue Property
- HTML DOM Input Number defaultValue Property
- HTML DOM Input Color defaultValue Property
- HTML DOM Input Email defaultValue Property
- HTML DOM Input Time defaultValue Property
- HTML DOM Input URL defaultValue Property
- HTML DOM Input Week defaultValue Property
- HTML DOM Input Password defaultValue Property
- HTML DOM Input Search defaultValue Property
- HTML DOM Textarea defaultValue Property
- HTML DOM Input Text size Property
- HTML DOM Input Text type Property
- HTML DOM Input Text value Property
- HTML DOM Input Text autocomplete Property
- HTML DOM Input Text autofocus Property

Advertisements