Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

249
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!