[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 752
  • Last Modified:

Update asp:listbox in window.opener page

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
jayh99
Asked:
jayh99
  • 9
  • 6
2 Solutions
 
CyrexCore2kCommented:
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
 
jayh99Author Commented:
[object]
0
 
jayh99Author Commented:
alert(window.opener.document.getElementById("Recipient"));

also returns [object]
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
CyrexCore2kCommented:
what about

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

?
0
 
jayh99Author Commented:
The javascript error returned when I run the script mentioned in my question is:

"Error: Unspecified error."

Not too useful...  :-)
0
 
jayh99Author Commented:
That returns [object] as well.
0
 
CyrexCore2kCommented:
Okay well that seems all well and good. What aboutttt

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

?
0
 
jayh99Author Commented:
[object] as well.
0
 
CyrexCore2kCommented:
And this still results in an error?

var opt = new Option('1', '1');
window.opener.document.getElementById("Recipient").options.add(opt);
0
 
jayh99Author Commented:
Yep, still the "Unspecified Error" in the javascript.
0
 
CyrexCore2kCommented:
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
 
CyrexCore2kCommented:
err, obviously define opt first in the main page.
0
 
jayh99Author Commented:
Now I receive the "Unspecified error" on the parent page when AddItem is called.
0
 
jayh99Author Commented:
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
 
jayh99Author Commented:
Thanks for the help with this!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 9
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now