-3

I want to add multiple select options with checkbox using javascript only.. not in jQuery.

<select class="form-control">
                          <option value="0">--- Please Select ----</option>
                          <option>html</option>
                        </select>
vinaykumar0459
  • 497
  • 1
  • 6
  • 19

2 Answers2

1

What you want to achieve is not clear but…
You can't place checkboxes as options inside a select element.

However, you can fake it doing that kind of things:

var expanded = false;
var checkboxes = document.getElementById("checkboxes");

function toggleCBs() {
  expanded = !expanded;
  if (expanded) {
    checkboxes.style.display = "block";
  } else {
    checkboxes.style.display = "none";
  }
}
.multiselect {
  width: 160px;
}

.selectBox {
  position: relative;
}

.selectBox select {
  width: 100%;
  font-weight: bold;
}

.overSelect {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
}

#checkboxes {
  display: none;
  border: 1px #dadada solid;
}

#checkboxes label {
  display: block;
}

#checkboxes label:hover {
  background-color: #1e90ff;
}
<form>
  <div class="multiselect">
    <div class="selectBox" onclick="toggleCBs()">
      <select class="form-control">
        <option value="0">---- Please Select ----</option>
      </select>
      <div class="overSelect"></div>
    </div>
    <div id="checkboxes">
      <label>
        <input type="checkbox"/>HTML</label>
      <label>
        <input type="checkbox"/>CSS</label>
      <label>
        <input type="checkbox"/>JS</label>
    </div>
  </div>
</form>

Highly inspired from: How to use Checkbox inside Select Option

I hope it helps.

Takit Isy
  • 9,688
  • 3
  • 23
  • 47
-1

maybe this is what you try to do :

Please select:</br>
    <input type='checkbox' name='checkbox1' id='checkbox1'><label for='checkbox1'>CheckBox 1</label></br>
    <input type='checkbox' name='checkbox2' id='checkbox2'><label for='checkbox2'>CheckBox 2</label></br>
    <input type='checkbox' name='checkbox3' id='checkbox3'><label for='checkbox3'>CheckBox 3</label>