Javascript need to send array to parent opener document

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="./manage_artists.pl" name="go_next">
<input type="hidden" name="collect_array">
</form>

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 manage_artists.pl 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.

Thanks!
jonscottaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Michel PlungjanIT ExpertCommented:
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

0
jonscottaAuthor Commented:
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.?

Thanks!
0
Michel PlungjanIT ExpertCommented:
That is of course one you define if you want the opener to have access to the array
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jonscottaAuthor Commented:
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.