django: how to pass template variable to javascript onclick routine?
This works
<div onclick="myFunction('{{ myVar }}')">
The only thing is that your myVar will become a string,
So if you need it as an object, an array... that's not what you need.
My solution:
- create button pass this below properties
<button type="button" onclick="check(varsize = '{{ size.sizeDes}}' ); return false type="btsize">`
- write script on header part
{% block javascript %} <script> function check(varsize) { document.getElementById("sizeid").value = varsize; } </script> {% endblock %}