Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS select onchange not firing

Tags:

Does anyone know any workarounds for this? I'm trying to use a select element for navigation. It looks something like this;

<select onchange="window.location=(this.options[this.selectedIndex].value)"> 

It works on all desktop browsers and it also works on my WP7 phone. It doesn't work on my iPhone (iOS 5.0).

like image 584
George Kendros Avatar asked Nov 04 '11 02:11

George Kendros


People also ask

Why is Onchange not working?

onchange is not fired when the value of an input is changed. It is only changed when the input's value is changed and then the input is blurred. What you'll need to do is capture the keypress event when fired in the given input. Then you'll test the value of the input against the value before it was keypressed.

What is select Onchange?

The onchange event occurs when the value of an element has been changed. For radiobuttons and checkboxes, the onchange event occurs when the checked state has been changed.

What is Onchange function?

The onchange attribute fires the moment when the value of the element is changed. Tip: This event is similar to the oninput event. The difference is that the oninput event occurs immediately after the value of an element has changed, while onchange occurs when the element loses focus.


1 Answers

iOS tends to not fire change events when you change the value of their inputs. I've documented this in more depth at the Device-Bugs tracker.

The workaround is to bind to the blur event instead. In the above example, use onblur and you'll be all set.

<select onblur="window.location=(this.options[this.selectedIndex].value)"> 
like image 163
Paul Irish Avatar answered Jan 04 '23 01:01

Paul Irish