Let's take a dictonary:
mydict = {
'color': "blue",
'brand': "Ford",
'year': 1969
}
We pass this dict to our template, then, in the template, we have a select list with options according to our dictionary keys (color, brand, year).
Now, I want to change some text in my rendered template regarding the selected option.
So we have some Jquery that is getting the value of the selected option, like this:
$('#myselect').change(function() {
var selected = $( "#myselect option:selected" ).text();
});
Now that we have the selected text, I would like to use it as a key to display a value from our dictionary. Something like this
$('#myselect').change(function() {
var selected = $( "#myselect option:selected" ).text();
$('#mytext').text('{{ mydict.selected }}');
});
But I guess mixing Django var and JS var like this, is not going to work... Any idea how I can do this ?