Input Text defaultValue Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Text

Description

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

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

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

Set the defaultValue property with the following Values

Value Description
value Sets the default value of the text field

Return Value

A String, representing the default value of the text field

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

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

First Name: <input type="text" id="myText" value="Mickey">

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

<script>
function myFunction() {/*from  w ww . j  a  v  a 2s. co m*/
    document.getElementById("myText").defaultValue = "new value";
}
</script>

</body>
</html>

Related Tutorials