Solved

Update asp:listbox in window.opener page

Posted on 2008-09-29
15
736 Views
Last Modified: 2008-10-04
I am trying to add a new item to an asp listbox using javascript from a child window.  I have tried the following code on my child page without any luck:

var to = window.opener.document.getElementById("Recipient");
     to.options.add(new Option('1','1'));


I have also tried:
var to = parent.document.getElementById("Recipient");
without any luck also.

The following code works fine on the parent page to add new items to the listbox:
   
function AddItem(){
    var to = document.getElementById("Recipient");    
     to.options.add(new Option('1','1'));
     }

Any help is greatly appreciated.
0
Comment
Question by:jayh99
  • 9
  • 6
15 Comments
 
LVL 14

Expert Comment

by:CyrexCore2k
ID: 22599736
try

alert(window.opener)

and verify that it doesn't say "null" if it does there's something wrong with how you're accessing the child window.
0
 
LVL 1

Author Comment

by:jayh99
ID: 22599748
[object]
0
 
LVL 1

Author Comment

by:jayh99
ID: 22599754
alert(window.opener.document.getElementById("Recipient"));

also returns [object]
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 14

Expert Comment

by:CyrexCore2k
ID: 22599771
what about

alert(window.opener.document.getElementById("Recipient").options);

?
0
 
LVL 1

Author Comment

by:jayh99
ID: 22599790
The javascript error returned when I run the script mentioned in my question is:

"Error: Unspecified error."

Not too useful...  :-)
0
 
LVL 1

Author Comment

by:jayh99
ID: 22599803
That returns [object] as well.
0
 
LVL 14

Expert Comment

by:CyrexCore2k
ID: 22599816
Okay well that seems all well and good. What aboutttt

var opt = new Option('1', '1');
alert(opt);

?
0
 
LVL 1

Author Comment

by:jayh99
ID: 22599825
[object] as well.
0
 
LVL 14

Expert Comment

by:CyrexCore2k
ID: 22599845
And this still results in an error?

var opt = new Option('1', '1');
window.opener.document.getElementById("Recipient").options.add(opt);
0
 
LVL 1

Author Comment

by:jayh99
ID: 22599862
Yep, still the "Unspecified Error" in the javascript.
0
 
LVL 14

Expert Comment

by:CyrexCore2k
ID: 22599869
If that doesn't work try this. Add this function to the child page:

function AddItem(opt){
    var to = document.getElementById("Recipient");    
     to.options.add(opt);
}

And then on the main page try this:

window.opener.AddItem(opt);
0
 
LVL 14

Assisted Solution

by:CyrexCore2k
CyrexCore2k earned 25 total points
ID: 22599873
err, obviously define opt first in the main page.
0
 
LVL 1

Author Comment

by:jayh99
ID: 22599905
Now I receive the "Unspecified error" on the parent page when AddItem is called.
0
 
LVL 1

Accepted Solution

by:
jayh99 earned 0 total points
ID: 22599981
Very weird, but I got this working:

On Parent Page:

    function AddItem(Recipient){
    alert(Recipient);
    var to = document.getElementById("Recipient");    
    to.options.add(new Option(Recipient,Recipient));
     }

On Child Page

    function addRecipient(RecipientName){              
    window.opener.AddItem(RecipientName);
    }    

0
 
LVL 1

Author Comment

by:jayh99
ID: 22599984
Thanks for the help with this!
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question