PRB: Problem Adding New Option to Select Box in Another Frame in Internet Explorer 5

ID: Q237831


The information in this article applies to:


SYMPTOMS

In Internet Explore 4.0 it is possible to create a new option in one frame and add it to a select box in another frame. This functionality is not supported in Internet Explorer 5.

Using this functionality causes the following Java script error:

Object does not support this property or method
It causes the following VBScript error:
Error: Not implemented


CAUSE

This was not an intended functionality, which caused some instability. It was removed from Internet Explorer 5.


RESOLUTION

There are two ways to work around this. The first way is call Internet Explorer 5's new createElement method on the target frame. The second method is to create a subroutine in the target frame to create the option and then return a reference to it.


STATUS

This behavior is by design.


MORE INFORMATION

Steps to Reproduce Behavior

The following reproduces the problem and illustrates two workarounds. Note that workaround 1 is Internet Explorer 5 specific.
  1. Place the following frameset code into an HTML page:
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4 Final//EN">
    <HTML>
    <HEAD>
    <TITLE>Option Creation Example</TITLE>
    </HEAD>
    <frameset cols="200,*">
      <frame name=left src=left.htm>
      <frame name=right src=right.htm>
    </frameset>
    </HTML> 


  2. Place the following code into Left.htm:
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4 Final//EN">
    <HTML>
    <HEAD>
    <TITLE>Left Hand frame</TITLE>
    
    <script language=javascript>
    var rFrame;
    var rFrameDoc;
    var rForm;
    
    //------------  getFrame()
    //------------  Get references to objects in right frame
    function getFrame()
    {
       rFrame = parent.right;
       rFrameDoc = rFrame.document;
       rForm = rFrameDoc.testForm;
    }
    
    //------------  failOpt()
    //------------  Reproduces failure
    function failOpt(elName,inText,inValue)
    {
    //Get a reference to select box in the other frame
      var rSel = rForm(elName);
    
    //Create a new Option in this frame
      var myOpt = new Option(inText,inValue)
    
    //add option from this frame to select box in other frame
    alert("Check the select box to see if any item was added.");
    rSel.options[rSel.length] = myOpt;
    }
    
    //------------  addOpt()
    //------------  Workaround 1
    //------------  Does not require changes to right hand frame
    function addopt(elName,inText,inValue)
    {
    //Solution for Internet Explorer 5+ Only 
    
       var rSel = rForm(elName);
    
    //Use method on other frame to create option, returns a reference
       var oOption = rFrameDoc.createElement("OPTION");
    
    //set properties
       oOption.text=inText;
       oOption.value=inValue;
    
    //add option to select box in other frame
       rSel.options[rSel.length] = oOption;
    // prompt user to open the select box in the other frame to see the item
       alert("Check the select box to see if any item was added.");
    
    }  
    
    //------------  otherOpt()
    //------------  Workaround 2
    //------------  Requires function in right hand frame too
    function otherOpt(elName,inText,inValue)
    {
       var rSel = rForm(elName);
    
    //Call a function in the other frame that returns
    //a reference to a new option
       var oOption = rFrame.newOpt(inText,inValue);
    
    //Add option to select box in other frame
       rSel.options[rSel.length] = oOption;
    // prompt user to open the select box in the other frame to see the item
       alert("Check the select box to see if any item was added.");
    }  
    </script>
    </HEAD>
    
    <BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#FF0000" onload="getFrame()">
    Internet Explorer 5 cannot add an option created in this frame, to a select   box 
    <BR>across frames. Internet Explorer 4 does.
    <BR><BR/>
    <BR> type your option text if you like<BR/>
    
    <input type=text value="Option Text" name=optText><BR><BR>
    
    <input type=button name=trigger1 value="Reproduce Problem"
       onclick="failOpt( 'mainMenu',optText.value,optText.value );">
    <BR><BR>
    
    <input type=button name=trigger1 value="Workaround 1"
       onclick="addopt( 'mainMenu',optText.value,optText.value );">
    <BR><BR>
    
    <input type=button name=trigger2 value="Workaround 2"
       onclick="otherOpt( 'mainMenu',optText.value,optText.value );">
    <BR><BR>
    
    </BODY>
    </HTML> 


  3. Save the following code as Right.htm:
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4 Final//EN">
    <HTML>
    <HEAD>
    <TITLE>Right Hand frame</TITLE>
    
    <script language=javascript>
    
    //------------  newOpt()
    //------------ This function is only for workaround #2
    //------------  Creates a new Option and returns reference
    function newOpt(inText,inValue)
    {
    // Create element in this frame's tree
      var myOpt = new Option(inText,inValue)
    
    // return reference
      return myOpt
    }
    
    </script>
    </HEAD>
    
    <BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#FF0000">
    <form name="testForm">
    Use input form in left hand frame to update this select box
    <BR><BR>
    <select name="mainMenu">
    <option>Some Options</option>
    </select>
    
    </form>
    </BODY>
    
    </HTML> 


  4. Open Main.htm in the browser.


  5. In the left frame, click the button labeled Reproduce Problem to illustrate the problem.


  6. Again in the left frame, click the two workaround buttons. You will see the two possible workarounds illustrated there.



REFERENCES

For more information, please see the MSDN Web Workshop:

http://msdn.microsoft.com/workshop/default.asp

Additional query words: select box new option combobox


Keywords          : kbDHTML kbGrpInet kbIE500 kbDSupport 
Version           : WINDOWS:5.0
Platform          : WINDOWS 
Issue type        : kbprb 

Last Reviewed: August 3, 1999