Solved

Update asp:listbox in window.opener page

Posted on 2008-09-29
15
728 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
 
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
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…

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now