Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap dropdown checkbox select

I'm trying to customize a bootstrap dropdown with checkboxes and if I select a checkbox from dropdown the label name I want to be written on input dropdown delimited with ';' like in uploaded picture when dropdown is closed.

Here is a fiddle example.

enter image description here

like image 617
BurebistaRuler Avatar asked Apr 16 '14 08:04

BurebistaRuler


People also ask

How do I select a dropdown in Bootstrap?

To open the dropdown menu, use a button or a link with a class of . dropdown-toggle and the data-toggle="dropdown" attribute. The . caret class creates a caret arrow icon (), which indicates that the button is a dropdown.

How can I select a checkbox using option?

Approach: Create a select element that shows “Select options” and also create a div that contains CheckBoxes and style that using CSS. Add javaScript functionality which is called when the user clicks on div that contains the select element.


1 Answers

Not the most elegant solution - you will probably want to refine this somewhat, but this might get you started:

$(document).ready(function() {     $("ul.dropdown-menu input[type=checkbox]").each(function() {         $(this).change(function() {             var line = "";             $("ul.dropdown-menu input[type=checkbox]").each(function() {                 if($(this).is(":checked")) {                     line += $("+ span", this).text() + ";";                 }             });             $("input.form-control").val(line);         });     }); }); 
like image 191
Matthew Layton Avatar answered Sep 26 '22 17:09

Matthew Layton