The name
attribute from input checkbox
element identifies form data after submission.
We can also use the name value to reference form data using JavaScript on the client side.
The name
property sets or gets the value of the name attribute of a checkbox.
name |
Yes | Yes | Yes | Yes | Yes |
Return the name property.
var v = checkboxObject.name
Set the name property.
checkboxObject.name=name
Value | Description |
---|---|
name | Set the name of the checkbox |
A String type value representing the name of the checkbox.
The following code shows how to change the name of a checkbox.
<!DOCTYPE html>
<html>
<body>
<!-- w ww . j a va 2 s .c o m-->
A Checkbox: <input type="checkbox" id="myCheck" name="myname">
<button onclick="display()">Display name</button>
<button onclick="change()">Change name</button>
<script>
function display() {
var x = document.getElementById("myCheck").name;
console.log("The name is: " + x);
}
function change() {
var x = document.getElementById("myCheck").name = "newCheckboxName";
console.log("The name was changed to: " + x);
}
</script>
</body>
</html>
The code above is rendered as follows: