Checkbox nameProperty
Checkbox Object
Definition and Usage
The name property sets or returns the value of the name attribute of the checkbox element.
The name attribute is used to send data to the server after form submission, or to reference form data in JavaScript.
Note:After form submission, only form elements with a name attribute will have their data values transmitted.
Syntax
Set the name property:
checkboxObject.name="name"
Return the name property:
checkboxObject.name
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the name attribute
Example
Example
The following example outputs the name of the checkbox:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Example (example.com)</title>
<script>
function displayResult(){
var x=document.getElementById("myCheck").name;
alert(x);
}
</script>
</head>
<body>
<form>
<input type="checkbox" name="check1" id="myCheck">Do you like summer?
</form>
<button type="button" onclick="displayResult()">Display name</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Example (example.com)</title>
<script>
function displayResult(){
var x=document.getElementById("myCheck").name;
alert(x);
}
</script>
</head>
<body>
<form>
<input type="checkbox" name="check1" id="myCheck">Do you like summer?
</form>
<button type="button" onclick="displayResult()">Display name</button>
</body>
</html>
Try it yourself »
Checkbox Object Other Extensions