Javascript DOM HTML Input Button name Property get

Introduction

Get the name of a button:

var x = document.getElementById("myBtn").name;

Click the input button to display the value of its name attribute.

View in separate window

<!DOCTYPE html>
<html>
<body>
<input type="button"
       onclick="myFunction()"
       id="myBtn"
       name="myname"
       value="Test">

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

<script>
function myFunction() {/* ww w.  ja  va  2 s  .  co  m*/
  var x = document.getElementById("myBtn").name;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The name property sets or gets the name attribute of an input button.

The name attribute can identify form data after it has been submitted to the server.

Only form elements with a name attribute will have their values passed to the server.

Property Values

Value Description
name Specifies the name of the button

The name property returns a String representing the name of the input button.




PreviousNext

Related