On Tue, Aug 11, 2009 at 2:53 PM, WilsonOfCanada wrote:
>
> I want to access the string from the list that is in the dictionary:
>
> function changeArea()
> {
>alert({{list_areas.British_Columbia}});
> }
>
> I get what I want in the generated HTML:
>
> function changeArea()
> {
>
I want to access the string from the list that is in the dictionary:
function changeArea()
{
alert({{list_areas.British_Columbia}});
}
I get what I want in the generated HTML:
function changeArea()
{
alert(['Metro Vancouver', 'Metro Vancouver A', 'Sunshine Coast']);
}
Howev
On Aug 7, 9:31 pm, WilsonOfCanada wrote:
> Hellos,
>
> I was wondering how to use {{ }} variables in javascript functions.
>
> ex. onchange = "changeArea({{ mooman |safe|escapejs}});"
>
> Thanks
I had this problem too, it was pretty frustrating. I can to 2
different solutions.
1. new templat
On Aug 9, 6:19 am, WilsonOfCanada wrote:
> I tried that before, but it only seems to work when it is used on
> the .html file.
>
> onchange="changeArea('{{ list_areas.BC|safe|escapejs}}')
>
> I need it to be onchange="changeArea('{{ list_areas|safe|escapejs}}')
> so the function can use list_area
Can you show us the generated template HTML, and if possible, the
expected result?
That way we can work out the issue with your django templates, rather
than trying to guess your code.
2009/8/9 WilsonOfCanada :
>
> I tried that before, but it only seems to work when it is used on
> the .html fil
I tried that before, but it only seems to work when it is used on
the .html file.
onchange="changeArea('{{ list_areas.BC|safe|escapejs}}')
I need it to be onchange="changeArea('{{ list_areas|safe|escapejs}}')
so the function can use list_areas (My javascript and html are on
separate files).
On
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
That needs to be :
alert({{ selectedAreas.BC }});
Look at the documentation. This problem is fairly obvious if you do:
http://docs.djangoproject.com/en/dev/topics/templates/#variables
I'm not trying to be mean, but please look at the docs before you
I sent the variable as dictionary with lists
{'BC:['Vancouver', 'Kamloops'], AB:['Calgary']}
However, when I use the variable in the function, it is treated as a
string.
function changeArea(mooman)
{
alert(selectedAreas["BC"]);
}
This was not defined. Is there something more I need to
On Aug 8, 7:49 pm, WilsonOfCanada wrote:
> Thanks,
> It worked, but out of curiosity, what do the additional quotes change
> (why are they needed)?
They're needed in Javascript, not in Django. If you looked at the
generated source (via View Source in your browser) you could have seen
that the ou
Thanks,
It worked, but out of curiosity, what do the additional quotes change
(why are they needed)?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us
On Sat, Aug 8, 2009 at 6:34 PM, WilsonOfCanada wrote:
>
> I am not sure; I am just trying to pass the variable from the
> dictionary using render_to_response to a javascript function. The
> function is stored as a .js file. This is a part of the code I am
> using it for:
>
> {{ selectCity|safe }
No, I placed the spaces in so it is more readable (I tested with
spaces afterwards and they still do not work). The function is passed
in by:
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
I think your problem is just the spaces between the filters, try {{
mooman|safe|escapejs }}.
Other then that, as long as the mooman is set in the context... that
should work.
Luke
On Sat, Aug 8, 2009 at 12:34 PM, WilsonOfCanada wrote:
-BEGIN PGP
I am not sure; I am just trying to pass the variable from the
dictionary using render_to_response to a javascript function. The
function is stored as a .js file. This is a part of the code I am
using it for:
{{ selectCity|safe }}
The {{ selectCity|safe }} works but the {{ mooman | safe | es
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Wilson,
Are you referring to rendering JS with template tags, or actual
template tags in JS?
In the first case, you use them like any other template tag.
The second case is only possible if there is some JS library that uses
Django-like templates.
Hellos,
I was wondering how to use {{ }} variables in javascript functions.
ex. onchange = "changeArea({{ mooman |safe|escapejs}});"
Thanks
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To p
16 matches
Mail list logo