0

I want to add checkboxes via css to a Multi Select using IE 11. The css I use works in Edge etc. , but does not for IE 11.

CSS and code:

<style>
option:before 
{
    content: "☐ "
}

option:checked:before 
{
    content: "☑ "
}

<select class="ddlRole" id="ddlRole" style="width: 810px;" size="6" multiple="">
    <option value="1">Administrator</option>
    <option selected="selected" value="2">Manager</option>
    <option value="3">User</option>
    <option selected="selected" value="4">Sub Manager</option>
    <option value="8">new role test 5</option>
</select>

Alternatively I'll use a table with 2 columns, the first being a checkbox column, the next the text/name of the option. Possibly even an expanded Ul with Li?, Though I really would rather not.

Thanks

Neal Rogers
  • 498
  • 9
  • 27
  • Using actual checkboxes (and proper labels) might make more sense here to begin with, I think. Select fields with `multiple` are a bit nasty to use in the first place (from the UX perspective), and if you not liking how those display the selected options comes on top of that … then I’d switch. – 04FS Feb 25 '19 at 16:02
  • Possible duplicate of [CSS pseudo elements in select tag options in Internet Explorer](https://stackoverflow.com/questions/48765664/css-pseudo-elements-in-select-tag-options-in-internet-explorer) – MichaelM Feb 25 '19 at 19:37

1 Answers1

0

If you try to use HTML, CSS and JS than following example can work with all major browsers including IE.

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>

Output in IE 11:

enter image description here

Reference:

How to use Checkbox inside Select Option

If you want to have a solution using only CSS than you can also find it in above link.

other example with JQuery:

Deepak-MSFT
  • 10,379
  • 1
  • 12
  • 19