No offense, but by saying "in the same script," you make it clear that you have a fundamental misunderstanding of what's going on.

A CGI script (in any language) runs on a web server. A web browser asks the server for a particular URI by making an HTTP request, and the server runs an instance of the CGI, sending its output to the browser as an HTTP response. This output is typically HTML, but it could be plain text, image data, something else, or as sounds likely in your case, an HTML page that includes some Javascript code.

Your web browser receives this HTML page and executes the Javascript found within it. This Javascript may have been output by the CGI, but it's not "the same script" in any meaningful sense. It's a different script in a different language running on a different machine. This Javascript may now make its own calls back to the server, but these will be new HTTP connections, even if these connections fire up new instances of the same CGI. (Which is possible, since it could send different parameters to get a different response than the browser's initial request got, but it also sounds ugly.) But the CGI instance that was executed to send the page and code to the browser has already finished; there's no way to send data back to it.

To put it another way: HTTP is a one-shot communication method. You ask the server for something, it sends it, and that's the end. You can't talk back and forth with a program on the server end via HTTP. That's why cookies and sessions and other such technologies exist -- to make it possible to maintain state over this stateless protocol, so both ends can "remember" what's going on over multiple requests.

Aaron B.
Available for small or large Perl jobs; see my home node.


In reply to Re^5: Is it possible to copy arrays from Javascript to Perl variable in the same Perl CGI script? by aaron_baugher
in thread Is it possible to copy arrays from Javascript to Perl variable in the same Perl CGI script? by lightoverhead

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.