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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
Loop function in Javascript fails when combined with perl array


New User

Aug 26, 2015, 3:18 PM

Post #1 of 2 (1272 views)
Loop function in Javascript fails when combined with perl array Can't Post

I am taking backend perl variables and using it at the front end for display. Here is the code.

@head1 and @head2 are the variable names taken from perl script. I use that and display those headers of grid on webpage.

var headname1= "@head1";
var headname2= "@head2";

Now, if there are 100 headers, i would have to assign variables 100 times separately. so its better to make it dynamic. Taking values from backend and assigning it to javascript variable. This task will be dynamic. Here is my attempted code for that.

I hav taken all the headers from backend and assigned it to line_array. @line_arry is the name of that array. If i do @line_arry[0] and so on. appropriate values will be displyaed.

var headname=[]; 

for(var i=0;i<total_columns;i++) {
headname[i+1]= "@line_arry[(i)]";

This code doesnot work. It displays only the first column. i.e.

 headname[1] = "Order"; 
headname[2] = "Order";

Order is the name of the first header. In headname[2], header of second column should be displayed. but it still displays "Order"

If i write the below code, it displays first and second header.

headname[i+1]= "@line_arry[(0)]"; 
headname[i+1]= "@line_arry[(1)]";

"@line_arry" doesnt work whereas
"@line_arry[0], @line_arry[1] works.
Can anyone suggeest why it is not performing looping action using variable i

Veteran / Moderator

Aug 26, 2015, 4:11 PM

Post #2 of 2 (1261 views)
Re: [ash1351] Loop function in Javascript fails when combined with perl array [In reply to] Can't Post

You need to provide more details and context. Perl is a server side language and Javascript is a client side language.


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

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