How to change the placeholder property of this multiple select with checkboxes

I am currently using the following script to make all multiple select dropdowns selectable through check boxes. There are around 30 such multiselect boxes in my form. When I use the placeholder option to automatically get the select box's title, it only gets the page's title.

https://www.jqueryscript.net/form/jQuery-Plugin-For-Multi-Select-List-with-Checkboxes-MultiSelect.html

<select multiple title="example">
    <option value="1">One</option>
</select>

$(document).ready(function () {
    $('select[multiple]').multiselect({
        texts: {
            placeholder: $(this).attr('title')
        }
    });
});

2 answers

  • answered 2018-04-17 06:03 Abhishek Mishra

    I think you are trying to show the selected option as button title, if so this code should work for you.

    <select multiple title="example" id="multiple-select">
        <option value="1">One</option>
    </select>
    
    $('#multiple-select').multiselect({
      includeSelectAllOption: true,
      buttonText: function(options) {
        if (options.length == 0) {
          return 'example';
        } else {
          return options.length + ' Selected';
        }
      }
    });
    

  • answered 2018-04-17 06:24 TechyTee

    Got the answer from @smilyface:

    $.each($('select[multiple]'), function (key, selectbox) {
        $('#' + selectbox.id).multiselect({
            texts: {placeholder: $('#' + selectbox.id).attr('title')}
        });
    });