I have the following HTML:
<select id="testMe" name="test" multiple="multiple" size="5" style="width:270px">
<option value="test1">test1</option>
<option value="test2">test2</option>
<option value="test3">test3</option>
<option value="test4">test4</option>
<option value="test5">test5</option>
<option value="test6">test6</option>
<option value="test7" selected="selected">test7</option>
<option value="test8">test8</option>
</select>
And the following jQuery code:
MySite.Common.moveScrollBar = function(selectID) {
var testSel = jQuery('#'+selectID + ' :selected').val();
jQuery('#'+selectID + ' option[value=' + testSel +']').attr('selected', true);
};
The reason for the jQuery code is to show the selected option in a select box when a page is initially loaded (fixed size select with dynamic number of values).
I have had to do this as IE does not seem to move the scrollbar to the selected item in the list when the HTML is initially rendered on page load.
Any ideas?
Auto scrolling does not work in IE if
multiple="multiple"is set.See similar question:
How to get first selected item in an asp:ListBox with SelectionMode="Multiple" to appear at top?