In a Perl CGI script, I need to increment a Perl array index inside a <script>
element to add each value in an array in each HTML
<p id="para1">
<p id="para2">
<p id="para3">
...
<p id="paraN">
one by one.
The number of <p>
tags and the length of the Perl array variable is same.
I tried using JavaScript to increment the Perl array index variable, but it's not working.
Is there any other way possible to do this?
Sample code:
#!/usr/bin/perl
print "content-type:text/html\n\n";
my @jslabel = ('1', '2', '3');
print <<EOF;
<html>
<head>
</head>
<body>
<p id="para0"> hi </p>
<p id="para1"> hi </p>
<p id="para2"> hi </p>
</body>
<script>
for( var i = 0; i < 3; i++ )
{
document.getElementById("para"+i).innerHTML = $jslabel[i];
}
</script>
</html>
EOF
The web page should show like this:
1
2
3
But, the outcome for the given code:
1
1
1
How to achieve the desired result?