Search w3schools.com:

SHARE THIS PAGE

Text value Property

Text Object Reference Text Object

Definition and Usage

The value property sets or returns the value of the value attribute of a text field.

The value property contains the default value OR the value a user types in (or a value set by a script).

Syntax

Set the value property:

textObject.value="value"

Return the value property:

textObject.value


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The value property is supported in all major browsers.


Example

Example

Display the value of the text field:

<html>
<head>
<script>
function displayResult()
{
var x=document.getElementById("email").value;
alert(x);
}
</script>
</head>
<body>

<form>
Email: <input type="text" id="email">
</form>

<button type="button" onclick="displayResult()">Display value</button>

</body>
</html>

Try it yourself »


Examples

More Examples

Form validation

Dropdown list in a form

Another dropdown list


Text Object Reference Text Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]