
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
HTML DOM Input Checkbox Name Property
The HTML DOM Input Checkbox name property returns a string, which is the value of the name attribute of input checkbox. User can also set it to a new string.
Syntax
Following is the syntax −
- Returning string value
inputCheckboxObject.name
- Setting name attribute to a string value
inputCheckboxObject.name = ‘String’
Example
Let us see an example of Input Checkbox name property −
<!DOCTYPE html> <html> <head> <title>Name Attribute of Checkbox</title> </head> <body> <form id="Form"> <div> Enable new name: <input id="formID" type="checkbox" name="formID"> </div> </form> <button onclick="getFormID()">Change Name Attribute</button> <div id="nameAttr"></div> <script> function getFormID(){ var oldNameAttr = document.getElementById("formID"); var newNameAttr = document.getElementById("nameAttr"); if(oldNameAttr.checked == true){ oldNameAttr.name = 'newFormID'; newNameAttr.textContent = 'Updated value of name attribute: '+oldNameAttr.name; } else { newNameAttr.textContent = 'Check the checkbox'+ ', current value of name attribute: '+oldNameAttr.name ; } } </script> </body> </html>
Output
This will produce the following output −
Before checking ‘Enable new name’ checkbox −
After checking ‘Enable new name’ checkbox −
Advertisements