Click here to Skip to main content
15,881,715 members
Articles / Web Development / HTML
Tip/Trick

Multi-select Check Box List or Checkbox Dropdown with Select All Option

Rate me:
Please Sign up or sign in to vote.
3.74/5 (6 votes)
11 Jul 2019CPOL 198.8K   5.2K   7   9
How to create a checkbox list using simple HTML and jQuery

Introduction

Check Box list is useful to allow the user to select multiple options in a select box. But in this case, multiple options can be selected by holding down the control (ctrl) button and the user hates that. Instead of using the multiple attributes in HTML, you can use jQuery to make the multi-select checkbox dropdown.

This is a simple HTML Control with jQuery & CSS that you can use in any web programming language.

Live Demo

Using the Code

I wrote an extension method using jQuery, you can define your dropdown select control and call CreateMultiCheckBox method.

This method will simply convert your select control into multi-select checkbox list control.

XML
<select id="test">
  <option value="1">American Black Bear</option>
  <option value="2">Asiatic Black Bear</option>
  <option value="3">Brown Bear</option>
  <option value="4">Giant Panda</option>
  <option value="5">Sloth Bear</option>
  <option value="6">Sun Bear</option>
  <option value="7">Polar Bear</option>
  <option value="8">Spectacled Bear</option>
</select>

Convert Select Into Multi Select Checkbox

Here "test" is your control id, you can also pass default options, such as width, height & default title of control.

JavaScript
$(document).ready(function () {
  $("#test").CreateMultiCheckBox({ width: '230px',
             defaultText : 'Select Below', height:'250px' });
});

Download

I put CSS and jquery on the same page, you can separate according to your project. Here is the full download TestMultiCheckbox.zip .

History

  • 11th July, 2019: Initial version

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionUsing optgroups in multicheckbox Pin
Member 151853695-May-21 9:53
Member 151853695-May-21 9:53 
Question$_POST wrong Pin
lapix8-Oct-20 3:32
lapix8-Oct-20 3:32 
QuestionGreat solution. Pin
Member 1046221617-Sep-20 5:46
Member 1046221617-Sep-20 5:46 
AnswerRe: Great solution. Pin
Member 1046221617-Sep-20 21:12
Member 1046221617-Sep-20 21:12 
QuestionInprovment Pin
Klaus Kurzawa12-Jul-19 18:55
Klaus Kurzawa12-Jul-19 18:55 
QuestionDownload code link not working Pin
Tom-Sacramento12-Jul-19 9:17
Tom-Sacramento12-Jul-19 9:17 
QuestionDownload link no work Pin
Edward Ocando12-Jul-19 6:03
Edward Ocando12-Jul-19 6:03 
GeneralMy vote of 5 Pin
jgakenhe12-Jul-19 3:24
professionaljgakenhe12-Jul-19 3:24 
That's actually quite nice! You should include all of your code in the Tip Trick and explain it. I was looking through it by way of your demo link.
PraiseMulti-select check box Pin
Member 1416447312-Jul-19 1:22
Member 1416447312-Jul-19 1:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.