Javascript Reference - HTML DOM Input Email value Property








The value property sets or gets the value attribute of an email field.

Browser Support

value Yes 10.0 Yes Yes Yes

Syntax

Return the value property.

var v = emailObject.value

Set the value property.

emailObject.value=text

Property Values

Value Description
text Set a single e-mail address, or a list of e-mail addresses




Return Value

A String type value representing a comma-separated list of emails.

Example

The following code shows how to get the email address of an email field.


<!DOCTYPE html>
<html>
<body>
<!--from  w w w  .ja v a2 s . co m-->
E-mail: <input type="email" id="myEmail" value="abc@example.com">
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
    var x = document.getElementById("myEmail").value;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to change the email address of an email field.


<!DOCTYPE html>
<html>
<body>
<!--  w  w  w  .  jav  a 2  s . c o m-->
E-mail: <input type="email" id="myEmail" value="aaa@example.com">
<button onclick="myFunction()">test</button>
<p id="demo"></p>

<script>
function myFunction() {
    document.getElementById("myEmail").value = "anc@example.com";
}
</script>

</body>
</html>

The code above is rendered as follows: