How can I declare a global variable in html and javascript for a django template page. I want to make display_language to be a global variables.
<script>
function onChange(){
if (xmlHttp.readyState==4 && xmlHttp.status==200) {
//request is successful. So retrieve the values in the response
display_language = xmlHttp.responseText.split(';');
alert("response: " + display_language);
}
}
</script>
<html>
<body>
{% ifequal item.lang display_language %}
{{item.text.strip}}
{% endifequal %}
</body>
</html>
Variables in JavaScript are implicitly global, so unless they are within a function and prefixed with the var keyword, they will be globally accessible
This is global
This is also global
This is local