Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

223
Visualizações
How to update the options (django queryset variable) of select tag based on the value of onchange event in django template?

I will need to update the option values after a selection in Django template?

For example,

<select id="state" type="text" name="state" onChange="update()">
   <option value="">Select state</option>
   {% for state in state %}
   <option value="{{state.id}}"
       {{state.name|capfirst}}
   </option>
   {% endfor %}
</select>

After selection of the state I want to update the city queryset according to the selected state. For example, if anyone select California as their state, I want to just give the options of the cities that are inside California state.

<select id="city" type="text" name="city">
   <option value="">Select city</option>
   {% for city in city %}
   <option value="{{city.id}}"
       {{city.name|capfirst}}
   </option>
   {% endfor %}
</select>

Can anyone suggest what would be the best way to approach this?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda