What are you trying to do? Note, the Python code in the view is executed on
the server side, before the HTML page is sent to the browser. The
Javascript code is executed by the browser itself once the HTML page has
been rendered. Once the page is in the browser, no Python code can run
there -- your Python code and Javascript cannot iteract. You can use Python
to write Javascript on the server, but the Python cannot dynamically
generate or change the Javascript in the browser.
Anthony
On Monday, July 30, 2012 1:55:14 PM UTC-4, curiouslearn wrote:
>
> Is it possible to pass a javascript variable to python code in a
> web2py view? The only questions and answers I have seen this in the
> forum are about how to do this for the URL() function. I want to know
> if this is possible for the "for" loop.
>
> For example:
>
> <script>
> var numrows = 5;
>
> {{for i in range(numrows):}}
> //do something here
> {{pass}}
>
> </script>
>
> The above does not work. Is there a way that above can be made to
> work? If so, can above work for cases in which the javascript variable
> is an array or a json object.
>
> Thank you.
>
--