0

Select with option tag is working fine, but I need in that option either a radio button or a check box should be there so it will be easier to select the specific dropdown value. I tried using multiple keyword but that doesnt solve my problem

I tried using multiple keyword but that doesnt solve my problem

<select name="location" id="location" class="form-control">
<option value="NULL">Select Location</option>
<option value="Mumbai">Mumbai</option>
<option value="Navi Mumbai">Navi Mumbai</option>
<option value="Thane">Thane</option>
<option value="Kalyan">Kalyan</option>
<option value="Pune">Pune</option>
<option value="Hyderabad">Hyderabad</option>

The same with a checkbox or radio button select option next to the each name

2 Answers2

1

## This should help ##

This should help

var expanded = false;

function showCheckboxes() {
  var checkboxes = document.getElementById("checkboxes");
  if (!expanded) {
    checkboxes.style.display = "block";
    expanded = true;
  } else {
    checkboxes.style.display = "none";
    expanded = false;
  }
}
.multiselect {
  width: 200px;
}

.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="showCheckboxes()">
      <select>
        <option>Select an option</option>
      </select>
      <div class="overSelect"></div>
    </div>
    <div id="checkboxes">
      <label for="one">
        <input type="checkbox" id="one" />First checkbox</label>
      <label for="two">
        <input type="checkbox" id="two" />Second checkbox</label>
      <label for="three">
        <input type="checkbox" id="three" />Third checkbox</label>
    </div>
  </div>
</form>
Naveen
  • 361
  • 2
  • 10
1

Try this

var expanded = false;

function showCheckboxes() {
  var checkboxes = document.getElementById("checkboxes");
  if (!expanded) {
    checkboxes.style.display = "block";
    expanded = true;
  } else {
    checkboxes.style.display = "none";
    expanded = false;
  }
}
.multiselect {
  width: 200px;
}

.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="showCheckboxes()">
      <select>
        <option>Select an option</option>
      </select>
      <div class="overSelect"></div>
    </div>
    <div id="checkboxes">
      <label for="one">
        <input type="radio" id="one" name="select"/>First checkbox</label>
      <label for="two">
        <input type="radio" id="two" name="select"/>Second checkbox</label>
      <label for="three">
        <input type="radio" id="three" name="select"/>Third checkbox</label>
    </div>
  </div>
</form>
Syed Mehtab Hassan
  • 1,297
  • 1
  • 9
  • 23