[dancer-users] interpolate a Javascript variable as to assign it's value to a TT variable

Andrew Beverley andy at andybev.com
Tue Sep 8 23:19:40 BST 2015


On Wed, 2015-09-09 at 01:13 +0300, Nikos Vaggalis wrote:
> Is it possible to interpolate a Javascript variable as to assign it's 
> value to a TT variable?

No, because the TT variable has already been rendered to its value once
the JS code runs.

> The scenario would be that from within the materialized template to 
> extract value pairs from DOM elements like sliders,select groups 
> etc,serialize them and save the resulting string into a cookie:
> 
> <script>
>  var getvalue = $(
> "#Brand").find(":selected").parent("optgroup").attr("label");
>  jsvar = {Brand:getvalue};
>  jsvar = JSON.strignify(jsvar);
>  [% SET session.ttvar= jsvar  ]%

       ^^ this would be rendered as blank when the JS runs

> </script>
>
> Imagine going through a series of elements,capturing the values which 
> can be used later on as parameters to a POST call i.e
> 
> {Brand:...,Price_from....,Price_to:...}
> 
> since they would be saved in a cookie which would be valid for the 
> rest of the session, they  could be reused by the same or another 
> route for purposes of for example reinstating or remembering the 
> previous state after the back button of the browser is hit
> 
> Of course, that could be done with an Ajax call but been thinking of
> alternative ways

Yeah, if you want them in your Dancer application, then you'd have to
somehow get the JS code to post them back into it, with an Ajax-type
call.

Andy




More information about the dancer-users mailing list