Javascript DOM HTML Input Email name Property set

Introduction

Change the name of an email field:

document.getElementById("myEmail").name = "newEmailName";

Click the buttons to display/change the value of the name attribute of the email field.

View in separate window

<!DOCTYPE html>
<html>
<body>

E-mail: <input type="email" id="myEmail" name="usremail">
<p id="demo"></p>
<button onclick="display()">Display name</button>
<button onclick="change()">Change name</button>

<script>
function display() {
  var x = document.getElementById("myEmail").name;
  document.getElementById("demo").innerHTML = "The name of the email field is: " + x;
}

function change() {//from  w w  w . j a v  a2 s .co m
  var x = document.getElementById("myEmail").name = "newEmailName";
  document.getElementById("demo").innerHTML = "The name was changed to: " + x;
}
</script>

</body>
</html>



PreviousNext

Related