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.
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.
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.
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); }); }); });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With