title: JavaScript on iOS: opening an HTML select element
body: <p>I'm not hopeful, but I'll ask just in case.</p>
  
  <p>I would like to be able to use JavaScript to open a select element in mobile Safari for iPhone/iPad.</p>
  
  <p>An extensive Google / Stack Overflow search shows that a lot of people would like to be able to do this in browsers in general, but it is not supported (why not, I wonder?). Various hacks have been suggested, from calling <code>focus()</code> on the select element and changing its <code>size</code> property to make more <code>option</code> elements visible, or constructing an entirely mock select element with <code>&lt;div&gt;</code> and <code>&lt;ul&gt;</code> elements. I would, however, like to use the native browser select controls in iPad and iPhone.</p>
  
  <p>I wondered, just maybe, someone might know of a proprietary Apple WebKit method to do this. It would be something like:</p>
  
  <pre><code>var myselect = document.getElementsByTagName("select")[0];
  myselect.open(); // this method doesn't exist
  </code></pre>
  
  <p>As a bonus, it'd also be handy to know of a boolean property that says whether the select element is currently open/active, or not (i.e. not just whether the element has focus). I know I can work this out by tracking click and change events, but a simple property would be useful.</p>
  
  <p>Wishful thinking?</p>
  
  <hr>
  
  <p><strong>UPDATE:</strong><br>
  I don't yet have the answer, but I've found that simulating a <code>mousedown</code> successfully opens a select element in Google Chrome, but not iPad or Firefox and so on:</p>
  
  <pre><code>function simulateMouseEvent(eventName, element) {
    var evt = document.createEvent("MouseEvents");
    evt.initMouseEvent(eventName, true, true, window,
      0, 0, 0, 0, 0, false, false, false, false, 0, null);
    element.dispatchEvent(evt);
  }
  
  simulateMouseEvent("mousedown", select);
  </code></pre>
  
  <p><strong>UPDATE:</strong><br>
  I've asked a related, but different (and similarly unanswered!) question on select boxes here: <a href="https://stackoverflow.com/questions/6207929/is-there-a-dom-event-that-fires-when-an-html-select-element-is-closed">Is there a DOM event that fires when an HTML select element is closed?</a></p>