in reply to Re: CGI: Saving javascript variables
in thread CGI: Saving javascript variables

Thanks...

I'm still having trouble understanding. You say
    > create a hidden field in the form and put in the folder.style information.
I'm still confused about how to grab the folder.style.display information. I guess I'm looking for a Perl function that does something like

param("folder_$id") = grabFromJavascript('folder.style.display', $id) +;
or, I guess more likely, a Javascript snippet that does something like
pushToCgiParam(id, folder.style.display)
or is it an html form that calls a javascript function, like
<input type="hidden" name="folder_12" value=folderStatus(12) />

throop

Replies are listed 'Best First'.
Re^3: CGI: Saving javascript variables
by jZed (Prior) on Oct 31, 2007 at 21:49 UTC
    There are only four ways I know for JavaScript to inform Perl about anything: 1) as a querystring on a GET request, 2) as a field in a form sent as a POST request, 3) as either GET or POST on an AJAX request, 4) by having JavaScript write to a cookie and then having Perl retrieve the cookie.

    You'd have to explain your overall goal for me to know which of those is best for you. I'm just answering the part of the question about sending something JavaScript knows to a Perl script.

    In a hidden field you could do something like these:
    <input type="hidden" name="folder_opts" id="folder_opts"> <script type="text/javascript"> document.getElementById('folder_opts').value = '{"f1":' + fi_value + ',"f2":' + f2_value + '}'; </script>
    Then on the Perl side, you'd read the folder_opts param, turn it into a Perl hash with one of the JSON modules.
Re^3: CGI: Saving javascript variables
by Gangabass (Vicar) on Nov 01, 2007 at 04:33 UTC

    I'm think the cookie way is the best choice for you.

    • on page load read cookies for folder.style.display info for each folder;
    • when style.display is changing write this info into cookie;

    So this is pure Javascript solution.