Built by Harvest

Chosen

Chosen is a javsacript plug-in that makes long, unwieldy select boxes much more user-friendly. It is currently available in both jQuery and Prototype flavors.

Project page on GitHub

Standard Select

Turns This
Into This

Multiple Select

Turns This
Into This

<optgroup> Support

Single Select with Groups
Multiple Select with Groups

Selected and Disabled Support

Chosen automatically highlights selected options and removes disabled options.

Single Select
Multiple Select with Groups

Default Text Support

Chosen automatically sets the default field text ("Choose a country...") by reading the select element's title value. If no title value is present, it will default to "Select Some Option" or "Select Some Options" depending on whether the select is single or multiple. You can change these elements in the plug-in js file as you see fit.

<select title="Choose a country..." style="width:350px;" multiple class="chzn-select">

Change / Update Events

  • Form Field Change

    When working with form fields, you often want to perform some behavior after a value has been selected or deselected. Whenever a user selects a field in Chosen, it triggers a "change" event* on the original form field. That let's you do something like this:

    $("#form_field").chosen().change( … );

    Note: Prototype doesn't offer support for triggering standard browser events. Event.simulate is required to trigger the change event when using the Prototype version.

  • Updating Chosen Dynamically

    If you need to update the options in your select field and want Chosen to pick up the changes, you'll need to trigger the "liszt:updated" event on the field. Chosen will re-build itself based on the updated content.

    • jQuery Version: $("#form_field").trigger("liszt:updated");
    • Prototype Version: Event.fire($("form_field"), "liszt:updated");

Why use Chosen?

  • User Friendly

    Instead of forcing your users to scroll through a giant list of items, they can just start typing the name of the item they were looking for. Non-matching entries are removed from view and choices can be selected using enter or mouse click.

  • Progressive Enhancement

    Because chosen replaces normal html select fields, you don't need to do anything special to make it work for browsers without javascript. You don't need to do anything special on the back end to handle the data either -- the form field still gets submitted as normal.

  • Painless Setup

    Add Chosen's files to your app and trigger the plug-in (see Setup below). Chosen automatically respects optgroups, selected state, the multiple attribute and browser tab order. You don't need to do anything else except customize the style as you see fit.

Setup

Using Chosen is easy as can be.

  1. Download the plug-in and copy the related files to your app.
  2. Activate the plug-in:
    • jQuery Version: Call the chosen plug-in - $(".chzn-select").chosen()
    • Prototype Version: Add the class chzn-select to appropriate select boxes.
  3. Disco.

Notable Forks

FAQs

  • Something doesn't work. Can you fix it?

    Yes! Please report all issues using the GitHub issue tracking tool.

  • What browsers are supported?

    All modern browsers are support (Firefox, Chrome, Safari and IE9). Legacy support for IE8 is also enabled.