Access Javacript variable's value in Web2py Code From view

97 views
Skip to first unread message

Yannick

unread,
Jun 18, 2009, 11:38:43 AM6/18/09
to web2py Web Framework, Massimo Di Pierro
Hello Mate,
I have a little problem here and not sure if it is even possible to do
so...
I was wondering if you know how to access javascript value in the
web2py python code from the view....

Here I'm trying to add a parameter to my URL and the value of that
param is a Javascript variable

##################
<script>
....
var param = 'value'

.... {{URL(r=request,c='static',f='action', args=[param])}}

.....
</script>
##################

This code gave me an error because the variable "param" is not defined
which is normal...
Do you know a way to get a param's value and put it as an argument to
my URL ??

Thanks for your help...

Cheers,
Yannick P.

mdipierro

unread,
Jun 18, 2009, 12:00:38 PM6/18/09
to web2py Web Framework
I assume param is javascript variable, not a Python variable:

##################
<script>
....
var param = 'value'

.... "{{URL(r=request,c='static',f='action')}}/"+param

.....
</script>
##################

Alexey Nezhdanov

unread,
Jun 18, 2009, 12:00:42 PM6/18/09
to web...@googlegroups.com
URL() is executed when generating page on server.
and param=... gets assigned _later_ when executing _already_generated_page_.

You can try though:
{{param='value'}}
var param={{=param}}


> Thanks for your help...
>
> Cheers,
> Yannick P.
>


--
Sincerely yours
Alexey Nezhdanov

JohnMc

unread,
Jun 18, 2009, 1:17:46 PM6/18/09
to web2py Web Framework
Little trick if you need to reference the same value later --

<span id="var1" var1 = "745"></span>

Using unique id's, jQuery makes it very easy to manipulate/reference
the contents. Not exactly XHTML compliant however.

Yannick

unread,
Jun 19, 2009, 9:55:14 AM6/19/09
to web2py Web Framework
Yes Massimo, param is a JS variable... Thanks for the note and help it
works fine...

Thank you all for your help on this

Cheers,
Yannick P.
Reply all
Reply to author
Forward
0 new messages