Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Workaround for bug with 0th <select> option in Mobile Safari on iPad?

In Mobile Safari on the iPad, it seems that if there is no option selected on a <select> element, then the user cannot select the 0th option before selecting another one first (try it on http://jsfiddle.net/PJTKq/ on an iPad).

To be more specific:

  1. Create a <select> element with two or more options.
  2. Clear it by programmatically setting selectedIndex = -1 or removing the "selected" attribute from all the <option> elements.
  3. Tap the select element and choose the 0th option. The selected index won't change.
  4. Tap the select element and choose another option, then tap it again and choose the 0th option. The selected index should change twice.

Does anyone know of a workaround (besides inserting an empty dummy option) that would allow moving directly from selectedIndex -1 to selectedIndex 0?

like image 888
kpozin Avatar asked Aug 09 '11 15:08

kpozin


People also ask

Why some websites are not opening in Safari iPhone?

Try to load a website, like www.apple.com, using cellular data. If you don't have cellular data, connect to a different Wi-Fi network and then load the website. If you're using a VPN (Virtual Private Network), check your VPN settings. If you have a VPN turned on, some apps or websites might block content from loading.

Why is my Safari not working?

Update Your iPhone Since Safari is a native iOS app, updating your iPhone is the only way to update the app too. Open Settings and tap General -> Software Update. Tap Download and Install if an iOS update is available. After the update is complete, open Safari and see if it's working again.


1 Answers

<script>    
// with jQuery
var iPad = !!navigator.userAgent.match(/iPad/i),
    select = "select";

if(iPad === true) {  
    $(select).prop("selectedIndex", 0);
}
</script>
like image 68
chrsr Avatar answered Nov 14 '22 22:11

chrsr