?
Solved

Update asp:listbox in window.opener page

Posted on 2008-09-29
15
Medium Priority
?
747 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
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
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 100 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

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!

Question has a verified solution.

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

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?
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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

770 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