Solved

Update asp:listbox in window.opener page

Posted on 2008-09-29
15
737 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

740 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