As said in the comments above: You are confusing the languagesand client/server side.

I assume that you are doing CGI and usually have the Javascript code transmitted to the webbrowser.

Javascript is usually executed in the browser and only printed out as a text string by the Perl script.

Your scalar $js contains a text string which contains characters which form syntactically correct javascript. Perl can't execute or parse that code (you would need a javascript interpreter for that in Perl, which probably can even be found on CPAN, but this has nothing to do with what you want to do).

If your CGI script needs to transmit something to the javascript code running in the browser you should look into AJAX (google it!), which is basically: The browser sends another request to your CGI script, which will return information that will be processed by the Javascript code in the browser to update the html in some way.


In reply to Re: Invoking Jscript function without actionevent by elmex
in thread Invoking Jscript function without actionevent by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.