HTML DOM Input Checkbox name Property

HTMLWeb DevelopmentFront End Technology

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.


Following is the syntax −

  • Returning string value
  • Setting name attribute to a string value = ‘String’


Let us see an example of Input Checkbox name property −

 Live Demo

<!DOCTYPE html>
<title>Name Attribute of Checkbox</title>
<form id="Form">
Enable new name: <input id="formID" type="checkbox" name="formID">
<button onclick="getFormID()">Change Name Attribute</button>
<div id="nameAttr"></div>
   function getFormID(){
      var oldNameAttr = document.getElementById("formID");
      var newNameAttr = document.getElementById("nameAttr");
      if(oldNameAttr.checked == true){ = 'newFormID';
         newNameAttr.textContent = 'Updated value of name attribute: ';
      } else {
         newNameAttr.textContent = 'Check the checkbox'+ ', current value of name attribute: ' ;


This will produce the following output −

Before checking ‘Enable new name’ checkbox −

After checking ‘Enable new name’ checkbox −

Updated on 30-Jul-2019 22:30:26