2011/3/28 allie <[email protected]>:
> Hello all,
>
> I'm new to webpy and have successfully put together a page using it.
> Now I would like to add some Javascript functionality that uses one of
> the variables that gets passed in with $def with. An abridged version
> of my code looks something like this:
>
> $def with (searchTerm)
> <html><head>
>    function OnLoad() {
>        ...
>        bar($searchTerm)
>        ...
>    }
> </head></html>
>
> As I suspected, this doesn't work. I assume there is a way around
> this, but I'm not sure what.

If searchTerm="foo", it will generate bar(foo) and that which is
invalid. You need to generate bar("foo").

Simple solution is to use bar("$searchTerm") if searchTerm is never
going to have quote characters in it.

Correct solution is to json ecode the string.

bar($:json_encode(searchTerm))

You need to add json_encode to template globals.

import simplejson

render = web.template.render("templates", globals={
    "json_encode": simplejson.dumps
})

Anand

-- 
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/webpy?hl=en.

Reply via email to