Please open the these examples on your iPhone.
The below code is the correct behavior.
<select id="selectMenu">
<option value="1">1</option>
<option value="2">2</option>
</select>
<input id="button" name="button" type="button" value="Click Me" />
var initEvt = function (el, type) {
var e = document.createEvent('MouseEvents');
e.initEvent(type, true, true, window);
el.dispatchEvent(e);
},
selMenu;
selMenu = document.getElementById('selectMenu');
document.getElementById('button').onclick = function () {
initEvt(selMenu, 'mouseover');
initEvt(selMenu, 'mousedown');
initEvt(selMenu, 'mouseup');
initEvt(selMenu, 'click');
}
If you add a setTimeout function it will not work.
<select id="selectMenu">
<option value="1">1</option>
<option value="2">2</option>
</select>
<input id="button" name="button" type="button" value="Click Me" />
var initEvt = function (el, type) {
var e = document.createEvent('MouseEvents');
e.initEvent(type, true, true, window);
el.dispatchEvent(e);
},
selMenu;
selMenu = document.getElementById('selectMenu');
document.getElementById('button').onclick = function () {
setTimeout(function () {
initEvt(selMenu, 'mouseover');
initEvt(selMenu, 'mousedown');
initEvt(selMenu, 'mouseup');
initEvt(selMenu, 'click');
}, 500);
}
http://jsfiddle.net/ghwfstmj/1/
Any idea why?
I also see a strange scroll issue. If there are two select menus it will scroll down to the button and back up if you use the native (select options) left and right arrows. If you click done it does not do this or click on them manually:
select {
display: block;
width: 100%;
}
#selectMenu { margin-bottom: 50px; }
#selectMenu2 { margin-bottom: 200px; }
<select id="selectMenu">
<option value="1">1</option>
<option value="2">2</option>
</select>
<select id="selectMenu2">
<option value="1">1</option>
<option value="2">2</option>
</select>
<input id="button" name="button" type="button" value="Click Me" />
var initEvt = function (el, type) {
var e = document.createEvent('MouseEvents');
e.initEvent(type, true, true, window);
el.dispatchEvent(e);
},
selMenu;
selMenu = document.getElementById('selectMenu');
document.getElementById('button').onclick = function () {
initEvt(selMenu, 'mouseover');
initEvt(selMenu, 'mousedown');
initEvt(selMenu, 'mouseup');
initEvt(selMenu, 'click');
}
http://jsfiddle.net/ghwfstmj/4/
Cheers!