Javascript examples for DOM HTML Element:Input Checkbox
The name property sets or gets the value of the name attribute of a checkbox.
Set the name property with the following Values
Value | Description |
---|---|
name | Sets the name of the checkbox |
A String, representing the name of the checkbox
The following code shows how to get the name of a checkbox:
<!DOCTYPE html> <html> <body> 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 of the checkbox is: " + x); } function change() {// w w w .ja va 2 s . c o m var x = document.getElementById("myCheck").name = "newCheckboxName"; console.log("The name was changed to: " + x); } </script> </body> </html>