CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
How to pass perl array(40,6) into JavaScript array(40,6)

 



TTMtech
Novice

Sep 26, 2003, 8:56 AM

Post #1 of 8 (2346 views)
How to pass perl array(40,6) into JavaScript array(40,6) Can't Post

Hi! All

I don't know how to pass multi dimensional perl array into javascript multi dimensional array of HTML file.If anyone can help me on that.


my $WebQt = $sr->{DLLs}->{WebQt};


my $return = $WebQt->WQ_GetLists(
$sr->{sid}, $VT_division_id, $VT_Dispositions, $VT_ReqTimes, $VT_Customers, $VT_JobTypes,
$VT_LayerCounts, $VT_MaterialTypes, $VT_MaterialThicknesses, $VT_CopperWeights, $VT_LineWidths,
$VT_SolderTypes, $VT_FinishTypes, $VT_Impedances, $VT_TestTypes, $VT_MVSizes, $VT_MVPadSizes, $VT_MVMaterialTypes,
$VT_error_message
);


my $return1 = $WebQt->WQ_GetPartNumberList($Fields->{customer_name}, $VT_division_id, $VT_PartNumbers);

my $PartNumbers = $VT_PartNumbers->Value;

I got result $VT_partNumbers-> value as two dimensional array(40,6) which gives part_id in each row and related information. Based on partId in dropdown box I wanted to display part number information on page.I don't know how to map it to pass it in javascript. I appricate if somebody can give some example on that.

Thanks in advance.


Hoschy
Novice

Jan 14, 2004, 12:44 AM

Post #2 of 8 (2335 views)
Re: [TTMtech] How to pass perl array(40,6) into JavaScript array(40,6) [In reply to] Can't Post

its not an answer,just an idea

Expot your values from the array out of perl to a file or database and then import it from java
but i donīnt know how to import from javascript

may be it helps


davorg
Thaumaturge / Moderator

Jan 14, 2004, 3:43 AM

Post #3 of 8 (2334 views)
Re: [TTMtech] How to pass perl array(40,6) into JavaScript array(40,6) [In reply to] Can't Post

You need to use your Perl array to print out HTML that contains JavaScript defining the JavaScript array.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


Hoschy
Novice

Jan 14, 2004, 7:17 AM

Post #4 of 8 (2332 views)
Re: [davorg] How to pass perl array(40,6) into JavaScript array(40,6) [In reply to] Can't Post

that is the point, if your perlscript printout HTML
wich contains the defining Javascript values, your are in need to print "javavar[x] = \"somevalue\";\n";
and thats a problem


davorg
Thaumaturge / Moderator

Jan 14, 2004, 7:55 AM

Post #5 of 8 (2330 views)
Re: [Hoschy] How to pass perl array(40,6) into JavaScript array(40,6) [In reply to] Can't Post

I really don't see why that's a problem.


Code
#!/usr/bin/perl 

use strict;
use warnings;
use CGI qw(:standard -no_xhtml);

print header;

my @array = qw(an array containing some data);

my $js = "\nvar a = new Array();\n";
for (0 .. $#array) {
$js .= qq(a[$_] = "$array[$_]";\n);
}

print start_html(-title => 'Test JavaScript Array',
-script => $js,
-onLoad => 'alert(a)'), "\n";
print p('View source to see JavaScript array'), "\n";

print end_html;


--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


Hoschy
Novice

Jan 14, 2004, 9:30 AM

Post #6 of 8 (2329 views)
Re: [davorg] How to pass perl array(40,6) into JavaScript array(40,6) [In reply to] Can't Post

something is wrong,
thats what i get with your method

Code
<title>index</title> 
</head>
<script language="javascript">

var text = new Array();
text[0] = "Last update on 14-01-2004
";
text[1] = "new indexpage
";
text[2] = "new updatefunction
";
text[3] = "F-Jugend training am Freitag 17:30 Uhr";


var jetzt = 0;

thats what written in the file

Last update on 14-01-2004
new indexpage
new updatefunction
F-Jugend training am Freitag 17:30 Uhr

and thats the scrip snip read the textfile

Code
open (INP, "<$datei") or die "can't open $datei: $!"; 
while(<INP>) {
chomp;
push(@satz, $_);
}
close (INP);

and your sample

Code
my $js = "\nvar text = new Array();\n";  
for (0 .. $#satz) {
$js .= qq(text[$_] = "$satz[$_]";\n);
}


on my local computer all is fine, but not if it uploaded

sorry hoschy


davorg
Thaumaturge / Moderator

Jan 14, 2004, 9:52 AM

Post #7 of 8 (2328 views)
Re: [Hoschy] How to pass perl array(40,6) into JavaScript array(40,6) [In reply to] Can't Post


In Reply To
on my local computer all is fine, but not if it uploaded


What operating system and web server is running on the two computers?


In Reply To
sorry hoschy


Nothing to apologise for as far as I can see.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


Hoschy
Novice

Jan 14, 2004, 1:47 PM

Post #8 of 8 (2325 views)
Re: [davorg] How to pass perl array(40,6) into JavaScript array(40,6) [In reply to] Can't Post

loacal is a win2k just activestate perl installed
and the webserver is a unix system with apache
and the same perl version.

the fact i wonder why is, all lines , how much it will be,
are not correct ecxept the last one....

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives