Javascript DOM HTML Input Submit name Property set

Introduction

Change the value of the name attribute of a Submit button:

document.getElementById("mySubmit").name = "newName";

Click the buttons below to display and change the value of the name attribute of the Submit button.

View in separate window

<!DOCTYPE html>
<html>
<body>

<input type="submit" name="submit1" id="mySubmit">
<p id="demo"></p>
<button onclick="display()">Display name</button>
<button onclick="change()">Change name</button>

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

function change() {//from www  .j a  va 2s  . c  o m
  var x = document.getElementById("mySubmit").name = "newName";
  document.getElementById("demo").innerHTML = "The name was changed to: " + x;
}
</script>

</body>
</html>



PreviousNext

Related