[CTS] Some Javascript Problem

  • From: "Tang Hion Koon" <tanghk@xxxxxxxxxxxx>
  • To: <computertalkshop@xxxxxxxxxxxxx>
  • Date: Tue, 6 Apr 2004 19:02:26 +0800

Hi all,

This javascript driving me crazy. Hope anyone on this list can help me out.

Scenario
--------
Parent window will open a pop-up child window. Then from child window, it will 
execute a script to populate a new value into parent window's list menu.

What I have in parent window is a menu with no value :-
        <select name=selectMember></select>

What I have in child window is the javascript to populate a value in parent 
window :-
        <script language=javascript>
                function addToMember(inID, inName) {
                        var myTarget = opener.document.frmName.selectMember;
                        var newoption = new Option(inName, inID, true, true);
                        myTarget.options[myTarget.length] = newoption;
                }
        </script>

So, what I do is execute the function with <a href="javascript:;" 
onClick="addToMember('1','Michael');">Click me</a>
What I am expecting is that the parent window's list menu will get populated 
with a new value.


Result
------
The above function will work in Mozilla and Netscape, but will not work (and 
crash) in IE.
Any Idea?


However, I have discovered that if I move the function from child window to 
parent window.
Then use self.opener.addToMember('1','Michael'); to execute the parent window's 
function, it will work fine in IE.
Why?

Anyone has any idea?
Thanks in advance.

Regards,
Tang



---------------------------------------------------------------------------
Computer Talk Shop http://www.computertalkshop.com
Un-subscribe/Vacation, http://www.computertalkshop.com/list_options.htm

List HowTo: http://www.computertalkshop.com/faq.htm

To join Computer Talk Shop's off topic list, please goto:
http://computertalkshop.com/other_cts_lists.htm
---------------------------------------------------------------------------

Other related posts:

  • » [CTS] Some Javascript Problem