title: Setting HTML check box to check using javascript
body: <p>I have a constructor that creates a series of checkboxes inside a loop.</p>
  
  <p>I am trying to set the checkboxes to checked, but it is not working. </p>
  
  <p>The code is below:</p>
  
  <pre><code>function customMultiSelect(pDiv, pOptions, inputID, currentSelected)
  {        
      this.Div = pDiv;
      this.options = pOptions;    
      this._initialise();
  
      for (var idxOption = 0; idxOption &lt; pOptions.length; idxOption++) {
  
          var checkbox = document.createElement("input");
          checkbox.type = "checkbox";
          checkbox.style.width = "30px";
          checkbox.style.border = "none";
          checkbox.style.float = "right";
  
          if (pOptions[idxOption] != "") {
              var arrTemp2 = pOptions[idxOption].split(",");
              var sText = arrTemp2[0];
  
              if (arrTemp2.length &gt; 1) {
                  sText = arrTemp2[1];
              }
  
              checkbox.value = arrTemp2[0];
              checkbox.id = inputID + "|" + idxOption;
              checkbox.checked = true;
              var textLabel = document.createElement("label");
              textLabel.appendChild(checkbox);
              textLabel.innerHTML += arrTemp2[1];
              textLabel.style.display = "block";
              textLabel.style.clear = "right";
  
          }
  
          this.Div.appendChild(textLabel);
      }
  
  }
  </code></pre>