Solved

Update asp:listbox in window.opener page

Posted on 2008-09-29
15
741 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: 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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Javascript: Range object 16 33
object method as an event handler 8 73
asp.net repeater server posting 5 36
How to send a javascript array via AJAX (jquery)? 3 40
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…
Suggested Courses

737 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