Javascript DOM HTML Input Email defaultValue Property set

Introduction

Change the default value of an email field:

document.getElementById("myEmail").defaultValue = "html@example.com";

Click the button to change the default value of the email field.

View in separate window

<!DOCTYPE html>
<html>
<body>

E-mail: <input type="email" id="myEmail" value="css@example.com">
<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/*from   ww w.java 2  s  .c  o  m*/
  document.getElementById("myEmail").defaultValue = "html@example.com";
}
</script>

</body>
</html>

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

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

The defaultValue contains the default value, while value contains the current value.

The defaultValue property accepts and returns a string value.




PreviousNext

Related