Please open these examples on your iPhone.
The following is the correct code.
<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'); }
http://jsfiddle.net/ghwfstmj/
If you add the 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 weird scroll issue. If there are two selection menus, they will scroll down to the button and back up if you use your own (select options) left and right arrows. If you click the "Finish" button, this will not happen 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/
Hooray!