1

So, I have the following HTML:

<div class="toolsIndexSelectContainer">
      <select id="Clients" class="toolsIndexSelect disableElement">
          <option>Item</option>         
          <option>Item 2</option> 
          <option>Item 3</option> 
      </select>
</div>

When I click on the surrounding div with class toolsIndexSelectContainer, I would like the select to dropdown and show the items inside. I have this jQuery:

$("div[class~='toolsIndexSelectContainer']").click(function () {
    $(this).children("select").focus();
});

But, focus() does not work. I tried click() and Chrome just blows up on me. Is there a way to do this?

ScubaSteve
  • 7,724
  • 8
  • 52
  • 65
  • No, You cannot do that on `select` element.. You cannot trigger to show the drop down options. – Selvakumar Arumugam Feb 14 '13 at 19:40
  • 1
    possible duplicate of [Is it possible to use JS to open an HTML select to show it's option list?](http://stackoverflow.com/questions/430237/is-it-possible-to-use-js-to-open-an-html-select-to-show-its-option-list) – Adam Feb 14 '13 at 19:41
  • http://stackoverflow.com/questions/1531882/custom-jquery-dropdown – samuelesque Feb 14 '13 at 19:43

3 Answers3

3

No, You cannot do that on select element.. You cannot trigger to show the drop down options.

Other option is to download a drop down plugin which basically simulates select features.

This ddSlick plugin seems to simulate select box property and also has a method to open the drop down options.

select You may use plugin's open method like $('#demoSetSelected').ddslick('open'); to open drop down options.

Selvakumar Arumugam
  • 79,297
  • 15
  • 120
  • 134
  • This is a bummer. I wanted add some rounded edges to the select. I've done it with textboxes. Oh well, it still looks good. – ScubaSteve Feb 14 '13 at 20:02
1

you can use something like the jquery Combobox . to convert the select to a combobox. Otherwise this is not possible with a normal select element

SNAG
  • 2,011
  • 2
  • 23
  • 43
1

This is a bit of a hack, but seems to work:

$(".toolsIndexSelectContainer").click(function () {
    $(this).find("#Clients").focus();
});
$("#Clients").focus(function(){
    this.size=$(this).find('option').length;
}).blur(function(){
    this.size=1;
});

fiddle to practice on: http://jsfiddle.net/As93t/

Mark Schultheiss
  • 32,614
  • 12
  • 69
  • 100