Microsoft KB Archive/237831

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

Article ID: 237831

Article Last Modified on 5/11/2006

-

APPLIES TO


 * Microsoft Internet Explorer 5.0

-



This article was previously published under Q237831



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.



Steps to Reproduce Behavior
The following reproduces the problem and illustrates two workarounds. Note that workaround 1 is Internet Explorer 5 specific.   Place the following frameset code into an HTML page: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4 Final//EN">   Option Creation Example     </HTML> </li> <li> Place the following code into Left.htm: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4 Final//EN"> <HTML>  Left Hand frame</TITLE>

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."); } </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> </li> <li> Save the following code as Right.htm: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4 Final//EN"> <HTML>  Right Hand frame</TITLE>

// 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 }

</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"> Some Options

</BODY>

</HTML> </li> <li>Open Main.htm in the browser.</li> <li>In the left frame, click the button labeled Reproduce Problem to illustrate the problem.</li> <li>Again in the left frame, click the two workaround buttons. You will see the two possible workarounds illustrated there.</li></ol>

<div class="references_section">