List Info

Thread: sending javascript value to TT2




sending javascript value to TT2
country flaguser name
India
2007-06-05 00:50:53

 I am using Javascript to read a cookie. Now,  I want  to
pass the  
value  to  TT2.
How to pass javascript(vari)  to TT2(rate_email)  ?

 


regards,
Rajkrishna N





In side  Template
[%- rate_email = PROCESS READCOOKIE name="name of
cookie" -%]


Block

[% BLOCK READCOOKIE %]
<script language="javascript">
<!---
function readcookie(name) {

        var name = name + "=";
        var ca = document.cookie.split(';');
        var value="";

        for(var i=0;i < ca.length;i++) {
                var c = ca[i];
                while (c.charAt(0)==' ') c =
c.substring(1,c.length);
                if (c.indexOf(name) == 0) 
value=c.substring(name.length,c.length);
        }
        if(! value) value=null;
}
var vari=readcookie([%- name -%]);
-->
</script>
[% END %]




_______________________________________________
templates mailing list
templatestemplate-toolkit.org
http://lists.template-toolkit.org/mailman/listinfo/t
emplates

Re: sending javascript value to TT2
country flaguser name
United States
2007-06-05 01:42:13
Rajkrishna Natarajan wrote:
> I am using Javascript to read a cookie. Now,  I want 
to pass the  
> value  to  TT2.
> How to pass javascript(vari)  to TT2(rate_email)  ?
[SNIP]

Javascript is processed in the browser (client-side), not by
TT(server-side). You should be accessing the cookie via your
backend/TT without the use of javascript.

-- Josh

_______________________________________________
templates mailing list
templatestemplate-toolkit.org
http://lists.template-toolkit.org/mailman/listinfo/t
emplates

Re: sending javascript value to TT2
user name
2007-06-06 03:36:29
On 6/4/07, Josh Rosenbaum <joshinfogears.com> wrote:
> Rajkrishna Natarajan wrote:
> > I am using Javascript to read a cookie. Now,  I
want  to pass the
> > value  to  TT2.
> > How to pass javascript(vari)  to TT2(rate_email) 
?
> [SNIP]
>
> Javascript is processed in the browser (client-side),
not by TT(server-side). You should be accessing the cookie
via your backend/TT without the use of javascript.

The TT can place the value into a hidden field or generate a
snippet
of JavaScript code to populate a variable....one of these
should do:

<input type="hidden" name="something"
value="[% something %]" />
<script>var something='[% something
%]';</script>

_______________________________________________
templates mailing list
templatestemplate-toolkit.org
http://lists.template-toolkit.org/mailman/listinfo/t
emplates

Re: sending javascript value to TT2
user name
2007-06-06 03:38:27
On 6/6/07, Bill Ward <billwards.net> wrote:
> On 6/4/07, Josh Rosenbaum <joshinfogears.com> wrote:
> > Rajkrishna Natarajan wrote:
> > > I am using Javascript to read a cookie. Now, 
I want  to pass the
> > > value  to  TT2.
> > > How to pass javascript(vari)  to
TT2(rate_email)  ?
> > [SNIP]
> >
> > Javascript is processed in the browser
(client-side), not by TT(server-side). You should be
accessing the cookie via your backend/TT without the use of
javascript.
>
> The TT can place the value into a hidden field or
generate a snippet
> of JavaScript code to populate a variable....one of
these should do:
>
> <input type="hidden"
name="something" value="[% something %]"
/>
> <script>var something='[% something
%]';</script>

Oh sorry I read the original question backward.

Your JavaScript could modify the value of the hidden field,
and then
submit it as form data.  But that has nothing to do with TT;
it's
basic CGI.

Or get clever with Ajax if you like, I suppose.

--Bill.

_______________________________________________
templates mailing list
templatestemplate-toolkit.org
http://lists.template-toolkit.org/mailman/listinfo/t
emplates

[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )