I am basically new in using Javascript and Django.
This is my script:
<script>
$(document).ready(function() {
$("#source").change(function() {
var el = $(this);
var reg = [];
var name = [];
{% for item in city %}
reg.push({{ item.reg }});
name.push({{ item.name }});
{% endfor %}
var a = getElementById("status").length;
for(val i = 0; i<a; i++){
if(el.val() == reg[i]){
$("#status").append("<option id = "+ reg[i] +">" + name[i] + "</option>");
}
}
});
});
</script>
This is my form:
<form method = "POST">
{% csrf_token %}
<select id="source" name="source">
<option>-----</option>
{% for item in region %}
<option id = {{ item.id }}>{{ item.name }}</option>
{% endfor %}
</select>
<select id="status" name="status">
<option>-----</option>
</select>
<select id="3">
<option>-----</option>
{% for item in zip %}
<option id = {{ item.cit }}>{{ item.num }}</option>
{% endfor %}
</select>
</form>
What I want to achieve is that the second dropdown box will display the contents under the selected item in the first dropdown box. I actually don't understand what am I doing wrong because it doesn't show any result whenever I load it, and there are no errors displayed too. What am I missing? Thanks in advance!
forloop anymore.