--- layout: default title: Examples - Select2 slug: examples ---

The basics

Select2 can take a regular select box like this...

and turn it into this...

Example code




    

Multiple select boxes

Select2 also supports multi-value select boxes. The select below is declared with the multiple attribute.

Example code




    

Placeholders

A placeholder value can be defined and will be displayed until a selection is made.

This works for multiple select boxes as well.

Example code




    

Loading array data

Select2 provides a way to load the data from a local array.

You can provide initial selections with array data by providing the option tag for the selected values, similar to how it would be done for a standard select.

Example code




    

Loading remote data

Select2 comes with AJAX support built in, using jQuery's AJAX methods.



      

Select2 will pass any options in the ajax object to jQuery's $.ajax function.

Disabled results

Select2 will correctly handled disabled results, both with data coming from a standard select (when the disabled attribute is set) and from remote sources, where the object has disabled: true set.

Example code




    

Tagging support

Select2 can be used to quickly set up fields used for tagging.

Note that when tagging is enabled the user can select from pre-existing options or create a new tag by picking the first choice, which is what the user has typed into the search box so far.

Example code