Javascript need to send array to parent opener document

Posted on 2008-11-03
Last Modified: 2013-11-05
Hi, I have used javascript to gather and validate input from a webpage form and sent the info to a perl script for processing.  'Also have used javascript in a child window to send the input to the parent opener.document page and sent this to the perl script.  But now I'm trying to send an array from the child window to the parent window to the perl script.  The array is made in the child document.form by using the multiple selection attribute.

Sending one value from the child page is being done like this:

opener.document.go_next.about_0.value = document.edit_form.about_0.value;

However, when sending the array from a multiple selection input, this syntax does not work like it does for a single value:

(in javascript funtion on child page)
opener.document.go_next.collect_array.value = document.edit_form.collect_array.value;

(using the html on child page)
<select name="collect_array" size="7" multiple="multiple"><option etc.></select>

(form on parent page)
<form method="post" action="./" name="go_next">
<input type="hidden" name="collect_array">

I've proven that the collect_array array can be sent directly to the perl script from a test form where it is parsed by

(perl script)
use CGI qw(:cgi-lib :standard);
@collect = $query->param('collect_array');
and an array results.

But going through the child to parent to perl script does not:

Error: Can't call method "param" on an undefined value at line 27.

I suspect that there is a javascript syntax which will equate the array on the edit_form document to the array on the opener.document.go_next document but I haven't found it yet.

'Have also tried about a dozen javascript functions to get the array from the child page to the parent opener page but no luck.

I'm willing to try a lot of code to get this to work but I still think there must be a single line of javascript which will equate the child input name array to the parent input name array.

Question by:jonscotta
    LVL 75

    Expert Comment

    by:Michel Plungjan
    No there is no such syntax

    So you need to do something like this
    var vals = "";
    var sel = document.edit_form.collect_array;
    for (var i=sel.selectedIndex; i < sel.options.length;i++) {
      vals += (sel.options[i].selected)?","+sel.options[i].value:"";
    if (vals) opener.document.go_next.collect_array.value = vals.substring(1); // gives a comma delimited string
    // OR
    if (vals) opener.someArray = vals.substring(1).split(','); // gives an array

    Open in new window


    Author Comment

    Hi, could you elaborate on

    if (vals) opener.someArray = vals.substring(1).split(','); // gives an array

    Where is this someArray in the opener document?  etc.?

    LVL 75

    Accepted Solution

    That is of course one you define if you want the opener to have access to the array

    Author Closing Comment

    Thank you for the solution which enabled the project to move ahead.  I'll have to spend a little more time on the line of code which is supposed to produce an array but that will be another day.  Meanwhile, a comma-separated string is being passed to the opener and then to the perl script.

    Featured Post

    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!

    Join & Write a Comment

    This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
    A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (,  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    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)

    755 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

    17 Experts available now in Live!

    Get 1:1 Help Now