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

ID: Q239657


The information in this article applies to:
  • Microsoft Internet Explorer (Programming) version 5


SYMPTOMS

When removing items from a <SELECT MULTIPLE> 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 this to be a bug in the Microsoft products listed at the beginning of this article.


MORE INFORMATION

This is a generic example of the code used in such an instance:



<FORM NAME="myform">
<SELECT NAME="widget" SIZE="3" MULTIPLE>
<OPTION>111111</OPTION>
<OPTION>222222</OPTION>
<OPTION>333333</OPTION>
<OPTION>444444</OPTION>
<OPTION>555555</OPTION>
<OPTION>666666</OPTION>
<OPTION>777777</OPTION>
<OPTION>888888</OPTION>
<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> 


REFERENCES

For additional information about issues with Select boxes, please click the article number below to view the article in the Microsoft Knowledge Base:

Q237831 PRB: Problem Adding New Option to Select Box in Another Frame in Internet Explorer 5
For more information, please see the MSDN Web Workshop:
http://msdn.microsoft.com/workshop/default.asp

Additional query words:

Keywords : kbDHTML kbGrpInet kbIE500bug kbDSupport kbIEFAQ
Version : WINDOWS:5
Platform : WINDOWS
Issue type : kbbug


Last Reviewed: January 27, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.