[Fixed]-Django and Javascript: dependent dropdown not working

1👍

I suspect this part:

            {% for item in city %}

                reg.push({{ item.reg }});
                name.push({{ item.name }});

            {% endfor %}

Unless {{ item.name }} evaluates to quoted values like 'cardiff', it’ll render like:

name.push(cardiff)

And that would be undefined. Maybe with some quotes:

name.push('{{ item.name }}')

Also, shouldn’t the for loop be like this ?

for(val i = 0; i<reg.length; i++){

There is also a typo in {{ item.cit }}.

You should also inspect and paste the generated HTML and JS.

!!! Pro-tip: You should use the JS debugger from your browser !!!

👤jpic

Leave a comment