Brittany
Brittany

Reputation: 41

How to use a Javascript value as a Perl variable

Is there a way to convert a javascript variable's value to a perl variable for use in the rest of the script?

The code that I have is:

  print "<TABLE border=22>";
  foreach $tmp (@splitarray) 
  {
    print "<TR>";
    $links = "<a href = '#' onclick='testingFunction(this);' >$tmp</a><BR>";
    print "<TD>$links</TD>";
  }
  print "<TD id='demo'></TD>";
  print "</TR>";
  print "</TABLE>";
}
print "<BR>";
print "<script type='text/javascript'>
       function testingFunction(link) 
       {
        var text = link.innerHTML;
        document.getElementById('demo2').innerHTML = text;
       }
       </script>";

###Information about the group name that is clicked
print "
<TABLE border=1 cellpadding='10'>
<CAPTION id ='demo2'>
 <strong></strong>
</CAPTION>
<TR>
 <TD>Members of group:</TD>
 <TD>(Names)</TD>
</TR>
<TR>
 <TD>Jobs that group can do:</TD>
 <TD>(Jobs)</TD>
</TR>
</TABLE>";

The split array variable is the group names. I would like to use the results from the javascript variable 'text' (which appear in the caption with the id of demo2) in other parts of my code but I would like for them to be stored as a Perl variable. For example, If a group that is clicked name is "Group 1" I would like the Perl variable $groupName to say "Group 1" when printed.

Even more specifically, my question is how do store the result of the Javascript OnClick event function in a perl variable?

Upvotes: 0

Views: 1256

Answers (1)

Liberat0r
Liberat0r

Reputation: 1871

This doesn't work that way. When the content has been sent to a browser, the perl script finished it's execution long time ago. If you want to know what user did on his computer, you have to send those information again to your content generating program (server in most cases ;)).

You might want to read This.

Upvotes: 1

Related Questions