views:

110

answers:

2

Hello,

I would like a select list that does the following:

  1. When the select list is open, display the list of descriptions.
  2. When the user selects an item, the select list will close an only the value will be displayed.

The reason for this is to conserve space as the values will be much shorter. I'm hoping that there's an answer in jQuery.

Thanks.

A: 

You can use this to show and hide list of descriptions inlcuded in span tags

It looks like your link has been removed. I looked at the Google cache of that page and it doesn't really answer my question. Please see Hober's comment for a good example of what I mean.
eli
A: 

Alright, I've worked it out:

$("#selectList").focus(function() {
  var selectedOption = $(this).find("option:selected");
  selectedOption.text(selectedOption.attr("description"));
});

$("#selectList").change(function() {
  var selectedOption = $(this).find("option:selected");
  selectedOption.attr("description", selectedOption.text());
  selectedOption.text(selectedOption.val());
});

var currSelOption = $("#selectList").find("option:selected");
currSelOption.attr("description", currSelOption .text());
currSelOption.text(currSelOption .val());

It could probably be optimized a bit.

eli
Please note two things with the above code:1. There is an issue when the user selects the same value twice. Since the select list is not actually changing, only the focus event would be triggered.2. When manipulating select lists, IE will reset the state of the select list to be closed. The user would need to select the list twice.
eli