A demo of an editable select list, plugin for jQuery

Read more at http://coffeescripter.com/2009/07/an-editable-select-list-plugin-for-jquery/ | More code at Coffeescripter.com

Just an example of the fact that it works even if the select list isn't visible from the start, or if you move the elements around

Features

Downloads

The JS-file

The CSS-file

The arrow image

Download all the files required

Note

When the plugin runs, it replaces the select with an input field, and sets the id of the input to the id of the select. The id of the select is then set to [real id]_hidden_select. If the element has no id, the id is set to editable-select[0-9]. Beginning with 1.3.2, it also copies all class names from the select to the input.

Example code

$(function() {
  $('.editable-select').editableSelect(
    {
      bg_iframe: true,
      onSelect: function(list_item) {
        alert('List item text: '+ list_item.text());
        // 'this' is a reference to the instance of EditableSelect
        // object, so you have full access to everything there
        alert('Input value: '+ this.text.val());
      },
      case_sensitive: false, // If set to true, the user has to type in an exact
                             // match for the item to get highlighted
      items_then_scroll: 10 // If there are more than 10 items, display a scrollbar
    }
  );
  var select = $('.editable-select:first');
  var instances = select.editableSelectInstances();
  instances[0].addOption('Germany, value added programmatically');
});

Feedback, feature requests, bug reports

If you have any feedback on this, please send it as a comment or email me at andy at-no-spam coffeescripter dot-no-spam com.

Credits

Thanks to Niklas Ohlsson for a lot of bug testing and helping out with feature ideas.

Changelog