Brethren,

From a webpage form, how do I save a javascript variable's state as a CGI::param?

Background: I'm coding a set of cgi-bin tools using CGI::Session. The pages display an indentured datastructure (read in from XML::Simple::XMLin). 'Folders' —parts of the datastructure—are hidden / exposed by clicking on icons. The icons are <IMG> tags with onclick methods that call a javascript function, toggleFolder.

In turn, toggleFolder toggles a javascript variable – folder.style.display – between 'block' and 'none'.

The problem: This is all working fine. But when the user reloads the page, (i.e, POSTs a 'submit' to save his inputs) the state information for all the folders is lost. The javascript variables aren't immediately accessible to the CGI::param variables. So the page comes back up with all the folders closed and the user has to click repeatedly to get back to the state before the Submit.

My question: How do I copy the value of a javascript variable (like folder.style.display) over to a CGI::param variable? Do I do it within the javascript (within the function definition of toggleFolder)? or from Perl?

Is there a module that I should be looking at to do this?

(I'm reasonable Perl programmer, but a novice at javascript. I'm refactoring / adapting someone else's code.)

thanks
throop


In reply to CGI: Saving javascript variables by throop

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.