Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

221
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda