diff --git a/js/jquery.mobile.forms.select.js b/js/jquery.mobile.forms.select.js index e899f989..23b1c932 100644 --- a/js/jquery.mobile.forms.select.js +++ b/js/jquery.mobile.forms.select.js @@ -22,7 +22,7 @@ $.widget( "mobile.selectmenu", $.mobile.widget, { nativeMenu: false }, _create: function(){ - + var self = this, o = this.options, @@ -33,7 +33,12 @@ $.widget( "mobile.selectmenu", $.mobile.widget, { selectID = select.attr( "id" ), label = $( "label[for="+ selectID +"]" ).addClass( "ui-select" ), - + + //IE throws an exception at options.item() function when + //there is no selected item + //select first in this case + selectedIndex = select[0].selectedIndex == -1 ? 0 : select[0].selectedIndex, + button = ( self.options.nativeMenu ? $( "
" ) : $( "", { "href": "#", "role": "button", @@ -41,7 +46,7 @@ $.widget( "mobile.selectmenu", $.mobile.widget, { "aria-haspopup": "true", "aria-owns": menuId }) ) - .text( $( select[0].options.item(select[0].selectedIndex) ).text() ) + .text( $( select[0].options.item( selectedIndex ) ).text() ) .insertBefore( select ) .buttonMarkup({ theme: o.theme,