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

258
Visualizações
Making an integerfield into selectable dropdown numbers from 0 to the value of the integerfield in django

I have been trying to make the value of an integerfield show up as a dropdown list with numbers ranging from 1 to the valueof the integer field for example 47 , the numbers between 1 and 47 will show up as a dropdown menu. i managed to get this code working:

HTML PAGE that's resposible for fetching the integerfield ID since i am displaying it in another model as a foreignkey, this is where i am also trying to make the dropdown list of numbers show up

{% for i in rayons %}

<option id="empla"value="{{ i.pk }}">{{ i.Nombre_des_Emplacments }}</option>

    <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>

<script>
var     n = {{ i.Nombre_des_Emplacments }};
for (var i = 0; i < n+1; i++) {
  //creates option tag
  jQuery('<option/>', {
    value: i,
    html: i
  }).appendTo('#empla');
}
</script>
{% endfor %}

Result : note that the Num field is what i am talking about and it's dependent on the previous field so when something other than A1 is selected the Num field will change

i want the numbers to show up as selectable options vertically on top of each other like a normal dropdown menu

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

Try this one

 {% for i in rayons %}
    <select id = "empla">
</select>
    <!-- <option id="empla"value="{{ i.pk }}">{{ i.Nombre_des_Emplacments }}</option> -->
    
        <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
    
    <script>
    var     n = {{ i.Nombre_des_Emplacments }};
    var empla = document.getElementById("empla")
    for (var i = 0; i < n+1; i++) {
      //creates option tag
      empla.options.add(new Option(i,i));
    }
    </script>
    {% endfor %}
about 4 years ago · Santiago Gelvez Relatório
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