Javascript DOM HTML Input Submit name Property get

Introduction

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

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

Click the button to display 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">
<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {//www  .  ja v  a 2 s. co m
  var x = document.getElementById("mySubmit").name;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The name property sets or gets the value of the name attribute of a submit button.

The name attribute will identify form data after submitting to the server.

Only form elements with a name attribute will be passed to the server.

Value Description
name Specifies the name of the submit button

The name property return a String representing the name of the submit button.




PreviousNext

Related