Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

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

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!
0
jonscotta
Asked:
jonscotta
  • 2
  • 2
1 Solution
 
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
 
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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