Microsoft KB Archive/239657

= FIX: Removing Non-Visible Items from an HTML SELECT Box Causes General Protection Fault (GPF) =

Article ID: 239657

Article Last Modified on 5/11/2006

-

APPLIES TO


 * Microsoft Internet Explorer 5.0

-



This article was previously published under Q239657



SYMPTOMS
When removing items from a  tag, removing more selected items than are viewable at once in the select box causes a GPF.



RESOLUTION
Create a temporary list of the selected elements, deselect all of them, and then remove the elements per the temporary list.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. This bug was corrected in Internet Explorer 5.01.



MORE INFORMATION
This is a generic example of the code used in such an instance:   111111 222222 333333 444444 555555</OPTION> 666666</OPTION> 777777</OPTION> 888888</OPTION> 999999</OPTION> </SELECT> <INPUT TYPE="BUTTON" VALUE="Crash or not" ONCLICK="RemoveSelectedItems"> </FORM> Here is the script code to remove the selected items that causes GPF. <SCRIPT LANGUAGE="JavaScript">

function RemoveSelectedItems {     var i

for ( i = document.myform.widget.options.length - 1; i >= 0; --i ) {        if (  document.myform.widget.options[ i ].selected ) {          document.myform.widget.options[ i ] = null }     }   }

</SCRIPT> To reproduce the problem, you need to select at least four items in this sample and then click the "Crash or not" button.

The root of the problem is removing the selected items. The workaround is to deselect the items, and save the list of selections in a temporary array.

The following is an example of how this might be coded: <SCRIPT LANGUAGE="JavaScript">

function RemoveSelectedItems {     var i, cnt var mywidget var selArray = new Array

myWidget= document.myform.widget

for ( i = myWidget.options.length - 1; i >= 0; --i ) {        if (  myWidget.options[ i ].selected ) {           myWidget.options[i].selected = false selArray[selArray.length]=i //document.myform.widget.options[ i ]=null }     }

for ( i = 0 ; i <= selArray.length; i++ ) {        myWidget.options[ selArray[i] ]=null }  }

</SCRIPT>

<div class="references_section">