The Wayback Machine - https://web.archive.org/web/20240906171901/https://www.geeksforgeeks.org/html-dom-input-text-defaultvalue-property/
Open In App

HTML DOM Input Text defaultValue Property

Last Updated : 16 Jun, 2023
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

The Input Text defaultValue Property in HTML DOM is used to set or return the default value of the Text Field. This property is used to reflect the HTML value attribute. The main difference between the default value and value is that the default value indicate the default value and the value contains the current value after making some changes. This property is useful to find out whether the text field have been changed or not. 

Syntax: 

  • It returns the defaultValue property.
textObject.defaultValue
  • It is used to set the defaultValue property.
textObject.defaultValue = value

Property Values: It contains single property value value which defines the default value for text field. 

Return Value: It returns a string value which represent the default value of the text field. 

Example 1: This example illustrates how to return Input Text defaultValue property. 

HTML




<!DOCTYPE html>
<html>
 
<head>
    <title>
        HTML DOM Input Text defaultValue Property
    </title>
</head>
 
<body style="text-align:center;">
    <h1>GeeksForGeeks</h1>
    <h2>DOM Input Text defaultValue Property</h2>
    <form id="myGeeks">
        <input type="text"
               id="text_id"
               name="geeks"
               value="GeeksForGeeks">
    </form><br>
    <button onclick="myGeeks()">Click Here!</button>
    <p id="GFG" style="font-size:20px;"></p>
 
    <!-- script to return the defaultValue Property-->
    <script>
        function myGeeks() {
            let txt = document.getElementById("text_id").defaultValue;
            document.getElementById("GFG").innerHTML = txt;
        }
    </script>
</body>
 
</html>


Output: 

 

  

Example 2: This example illustrates how to set Input Text defaultValue property. 

HTML




<!DOCTYPE html>
<html>
 
<head>
    <title>
        HTML DOM Input Text defaultValue Property
    </title>
</head>
 
<body style="text-align:center;">
    <h1>GeeksForGeeks</h1>
    <h2>DOM Input Text defaultValue Property</h2>
    <form id="myGeeks">
        <input type="text"
               id="text_id"
               name="geeks"
               value="GeeksForGeeks">
    </form><br>
    <button onclick="myGeeks()">
      Click Here!
    </button>
    <p id="GFG" style="font-size:20px;"></p>
 
    <!-- script to set the defaultValue Property-->
    <script>
        function myGeeks() {
            let txt =
                document.getElementById("text_id").defaultValue
                = "HelloGeeks";
 
            document.getElementById("GFG").innerHTML = txt;
        }
    </script>
</body>
 
</html>


Output: 

 

Supported Browsers: The browser supported by DOM input Text defaultValue Property are listed below:

  • Google Chrome 1 and above
  • Edge 12 and above
  • Firefox 1 and above
  • Opera
  • Safari 1 and above


Similar Reads

HTML | DOM Input Email defaultValue Property
The Input Email defaultValue property in HTML DOM is used to set or return the default value of Email Field. This property is used to reflect the HTML value attribute. The main difference between the default value and value property is that default value indicate the default value specified in the attribute while the value contains the current valu
2 min read
HTML | DOM Input Password defaultValue Property
The DOM Input Password defaultValue Property is used to set or return the default value of the Password Field. This Property is used to reflect the HTML value attribute . The main difference between the default value is that default value indicate the default value specified in the attribute while the value contains the current value after making s
2 min read
HTML | DOM Input Search defaultValue Property
The DOM Input Search defaultValue Property in HTML DOM is used to set or return the default value of the search Field. This property is used to reflect the HTML value attribute. The main difference between the default value and value is that the default value indicates the default value and the value contains the current value after making some cha
2 min read
HTML | DOM Input Week defaultValue Property
The DOM Input Week defaultValue property in HTML DOM is used to set or return the default value of a week field. It is the value specified in the value attribute. Syntax: It returns the defaultValue property.weekObject.defaultValueIt is used to set the defaultValue property.weekObject.defaultValue = value Property Values: value: It specifies the de
2 min read
HTML | DOM Input Month defaultValue Property
The DOM Input Month defaultValue property in HTML DOM is used to set or return the default value of a Month field. It is the value specified in the value attribute. Syntax: It returns the defaultValue property.monthObject.defaultValueIt is used to set the defaultValue property.monthObject.defaultValue = value Property Values: value: It specifies th
2 min read
HTML | DOM Input URL defaultValue Property
The DOM Input URL defaultValue Property in HTML DOM is used to set or return the default value of the URL Field. This property is used to reflect the HTML value attribute. The main difference between the default value and value is that the default value indicates the default value and the value contains the current value after making some changes.
2 min read
HTML | DOM Input Time defaultValue Property
The DOM Input Time defaultValue Property in HTML DOM is used to set or return the default value of the Time Field. This property is used to reflect the HTML value attribute. The main difference between the default value and value is that the default value indicates the default value and the value contains the current value after making some changes
2 min read
HTML DOM Input Color defaultValue Property
The DOM Input Color defaultValue Property in HTML DOM is used to set or return the default value of a Color picker. It is the value specified in the value attribute. Syntax: It returns the defaultValue property.colorObject.defaultValueIt is used to set the defaultValue property.colorObject.defaultValue = value Property Values: value: It specifies t
2 min read
HTML | DOM Input Radio defaultvalue Property
The Input Radio defaultValue Property in HTML DOM is used to set or return the default value of a Radio field. This property is used to reflect the HTML value attribute. The main difference between the default value and value is that the default value indicate the default value and the value contains the current value after making some changes. Thi
2 min read
HTML DOM Input DatetimeLocal defaultValue Property
The Input DatetimeLocal defaultValue property is used to set or return the default value of a local DateTime field. This property is used to reflect the HTML value attribute. The main difference between the default value and value is that the default value indicates the default value and the value contains the current value after making some change
2 min read
HTML | DOM Input Datetime defaultValue Property
The Input Datetime defaultValue property in HTML DOM is used to set or return the default value of a datetime field. This property is used to reflect the HTML value attribute. The main difference between the default value and value is that the default value indicates the default value of the property and the value contains the current value after m
2 min read
HTML | DOM Input Date defaultValue Property
The Input Date defaultValue Property in HTML DOM is used to set or return the default value of a date field. This property is used to reflect the HTML value attribute. The main difference between the default value and value is that the default value indicate the default value and the value contains the current value after making some changes. This
2 min read
HTML | DOM Input Hidden defaultValue Property
The Input Hidden defaultValue Property in HTML DOM is used to set or return the default value of a hidden field. This property is used to reflect the HTML value attribute. The main difference between the default value and value is that the default value indicates the default value and the value contains the current value after making some changes.
2 min read
HTML | DOM Input reset defaultValue Property
The Input reset defaultvalue Property in HTML DOM is used to set or return the default value of a reset field. This property is used to reflect the HTML value attribute. The main difference between the default value and value is that the default value indicates the default value and the value contains the current value after making some changes. Th
2 min read
HTML | DOM Input Checkbox defaultValue Property
The DOM Input Checkbox defaultValue Property is used to set or returns the default value of an Input Checkbox field. This property is used to reflect the HTML value attribute. The main difference between the default value and value is that the default value indicates the default value and the value contains the current value after making some chang
2 min read
HTML | DOM Input Submit defaultvalue Property
The Input Submit defaultValue Property in HTML DOM is used to set or return the default value of a submit field. This property is used to reflect the HTML value attribute. The main difference between the default value and value is that the default value indicates the default value and the value contains the current value after making some changes.
2 min read
HTML DOM Input Range defaultValue Property
The Input Range defaultValue Property in HTML DOM is used to set or return the default value of the slider control. This property is used to reflect the HTML value attribute. The main difference between the default value and value is that the default value indicates the default value and the value contains the current value after making some change
2 min read
HTML | DOM Input Number defaultValue Property
The Input Number defaultValue Property in HTML DOM is used to set or return the default value of the number Field. This property is used to reflect the HTML value attribute. The main difference between the default value and value is that the default value indicates the default value and the value contains the current value after making some changes
2 min read
HTML DOM Input Tel defaultValue Property
The Input Tel defaultValue property in HTML DOM is used to set or return the default value of the input tel field. This property is used to reflect the HTML value attribute. The main difference between the default value and value is that the default value indicates the default value and the value contains the current value after making some changes
2 min read
HTML | DOM Textarea defaultValue property
The DOM Textarea defaultValue Property is used to set or return the default value of the textarea field. Syntax: It is used to return the defaultValue property.textareaObject.defaultValueIt is used to set the defaultValue property:textareaObject.defaultValue = text/value Property Values: text: It specifies the default value of the text area. Return
2 min read
HTML | DOM Input Text value Property
The Input Text value property in HTML DOM is used to set or return the value of a value attribute of the input field. The value attribute specifies the initial value of the input Text Field. It contains the default value or the user types. Syntax: It returns the Input Text value property. textObject.valueIt is used to set the Input Text value prope
2 min read
HTML | DOM Input Text size Property
The Input Text size Property in HTML DOM is used to set or return the value of the size attribute of an Input Text Field. The size attribute is used to define the width of a text field. Its default value is 20. Syntax: It returns the Input Text size property.textObject.sizeIt is used to set the Input Text size property.textObject.size = number Prop
2 min read
HTML | DOM Input Text placeholder Property
The Input Text Placeholder property in HTML DOM is used to set or return the value of the placeholder attribute of a text field. The placeholder attribute specifies the short hint that describes the expected value of an input field. The short hint is displayed in the field before the user enters a value. Syntax: It returns the Input Text Placeholde
2 min read
HTML | DOM Input Text readOnly Property
The Input Text readOnly property in HTML DOM is used to set or return whether a text field should be read-only or not. It means that a user can not modify or changes the content already present in a particular element (However, a user can tab to it, highlight it, and copy the text from it) whereas a JavaScript can be used to change the read-only va
2 min read
HTML | DOM Input Text pattern Property
The Input Text pattern Property in HTML DOM is used to set or return the pattern attribute of an text field. It is used to specify the regular expression on which the input elements value is checked. Use the global title attribute to describe the pattern for helping the user. Syntax: It returns the Input Text pattern property.textObject.patternIt i
2 min read
HTML | DOM Input Text required Property
The Input Text required Property in HTML DOM is used to set or return whether Input Text Field should be filled or not when submitting the form. This property is used to reflect the HTML required attribute. Syntax: It returns the Input text required property.textObject.requiredIt is used to set the Input text required property.textObject.required =
2 min read
HTML | DOM Input Text name Property
The DOM Input Text name Property in HTML DOM is used to set or return the value of name attribute of a Textfield. The name attribute is required for each input field. If the name attribute is not specified in an input field then the data of that field would not be sent at all. Syntax: It returns the Input Text name property.textObject.nameIt is use
2 min read
HTML | DOM Input Text maxLength Property
The DOM Input Text maxLength Property in HTML DOM is used to set or return the value of maxlength attribute of a Text Input Field. It specifies the maximum number of characters that have been allowed in the text field. The default value of Input Text maxLength property is 524288. Syntax: It returns the Input Text maxLength property.textObject.maxLe
2 min read
HTML | DOM Input Text form Property
The DOM Input Text form Property in HTML DOM is used to return the reference of form containing the input Text field. It is a read-only property that returns the form object on success. Syntax: textObject.form Return Values: It returns a string value which specify the reference of the form containing the Input Text field. Example: This example illu
1 min read
HTML | DOM Input Text disabled Property
The DOM Input Text disabled Property is used to set or return the whether the Input Text Field must be disabled or not. A disabled Text Field is un-clickable and unusable. It is a boolean attribute and used to reflect the HTML Disabled attribute. It is usually rendered in grey color by default in all the Browsers.Syntax: It returns the disabled pro
2 min read