in reply to How do you pass a perl variable to a Javascript function

The key to this is to be clear that Perl is happening on the server, while Javascript is happening on the client. There is really no connection between the two. So, on the server you use Perl to create your webpage, which just happens to also build the Javascript code, including any variables that you might be using to build the code, the page and everything else.

Once all this is done, the webpage is generated and sent off to the client (the user's browser). At that point it is any normal webpage, and as far as the user is concerned, anything or any language could have created it. Now, the Javascript works as in any other page.

You can do the reverse and have Js "communicate" with Perl -- use Js to populate form or url variables to send them back to the server so Perl can now use it to do other things.

If you are using the above concept and it is not working, perhaps it would help to post any error messages you might have in the error log. Perhaps the Perl script is breaking elsewhere and not even generating the value that you are expecting in your webpage.

  • Comment on Re: How do you pass a perl variable to a Javascript function