Javascript DOM HTML Input Checkbox name Property get

Introduction

Get the name of a checkbox:

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

Click button to display the value of the name attribute of the checkbox.

View in separate window

<!DOCTYPE html>
<html>
<body>

Checkbox: <input type="checkbox" id="myCheck" name="myname">
<p id="demo"></p>

<button onclick="myFunction()">Test</button>

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

</body>
</html>

The name property sets or gets the name attribute of a checkbox.

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

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

The name property accepts and returns a String value.




PreviousNext

Related