Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8324439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:04:36+00:00 2026-06-09T00:04:36+00:00

In the following code i am trying to add an dropdown box to a

  • 0

In the following code i am trying to add an dropdown box to a tag. To do this i call a function onready and then add it.I have two issues here

1.The table has more than two thousand rows and there i use django pagination.But on ready the drop down box is populated for all the two thousand rows.How can i load the drop down box for the 100 rows i.e, is being paginated.So that it will be faster.
2.Also the drop down box are slower to show data to select.How can i rectify this.

Hope i am clear with the question

  {% extends "base/admin_base.html" %}
  {% load pagination_tags %}

  {% block content %}
  <script>

  $(document).ready(function() {
  $('font').css({'color':'red'})
     getcategory('1');
  });
  function getcategory(flag)
  {
     if($("#cgroup").val().trim() == "-1")
     {
        alertmsg+= "Select Category group\n"
     }  
     else
     {
        var html = "";
        var opt = "";
        var cgroup = $("#cgroup").val();
        html += '<select id="category" class="category">';
        html += '<option value="-1" class="cat">Select Category</option>';   
         {% for category in response_dict.category %}
           gp = '{{category.categorygroup.id}}' ;
           if(cgroup == gp)
           {
              html += '<option class="data" value="{{category.id}}">{{category.name}}</option>';  
           }
         {% endfor %}
           html += '</select>';
           if(flag == 1)
           {
              $(".tg").html('');
              $(".tg").append(html);
           }

     }
  }


  </script>
  <h1>Tag data</h1>
         {% autopaginate response_dict.taggeddata 100 %}
           <div align="right">{% paginate %}</div>
  <form action="/users/saveuser/" method="post">{% csrf_token %}
 <table>

   <tr><td><font>*</font>Select Category group for tagging</td><td> 
   <select id="cgroup" onchange="getcategory('1');">
   {% for group in response_dict.categorygroup %}
            <option value="{{group.id}}">{{group.name}}</option> 
   {% endfor %}
   </select>  
   </td></tr>

  </table>

  <b>
        <table>

         <tr><td><font>*</font>Select Category group for tagging</td><td> 
         <select id="cgroup" onchange="getcategory('1');">
         {% for group in response_dict.categorygroup %}
                  <option value="{{group.id}}">{{group.name}}</option> 
         {% endfor %}
         </select>  
         </td></tr>

        </table>
        </b>
        <table  id="box-table-a">
        <colgroup>
        <col class="vzebra-odd">
        </colgroup>
        <thead>
         <tr><th id="vzebra-comedy" scope="col">Field1</th><th id="vzebra-adventure" scope="col">Field2</th><th id="vzebra-comedy" scope="col">Field3</th><th id="vzebra-adventure" scope="col">Field4</th><th id="vzebra-comedy" scope="col">Field5</th><th id="vzebra-adventure" scope="col">Field6</th><th id="vzebra-comedy" scope="col">Tag</th><th id="vzebra-adventure" scope="col">Actions</th><thead></tr>
        <tbody>
         {% for td in response_dict.taggeddata %}
           <tr id="{{td.id}}">
           <td class="tg">Select category</td>
           </tr>
         {% endfor %}
        </tbody>
        </table>
         <input type="button" value="Add" id="addbtn" onclick="validate();"/>

  </form>
  {% endblock %}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T00:04:37+00:00Added an answer on June 9, 2026 at 12:04 am

    That is some pretty odd JavaScript you have there. For starters you should never be doing this.

    {% for category in response_dict.category %}
      gp = '{{category.categorygroup.id}}' ;
      if(cgroup == gp)
      {
        html += '<option class="data" value="{{category.id}}">{{category.name}}</option>';  
      }
    {% endfor %}
    

    It means that you are dumping out the same JavaScript over and over again. You should instead build a JavaScript array and loop over it with pure JavaScript. Just look at the rendered page you get from that code, it will be huge.

    // Build your array with Django templates or load it with ajax
    var data = [...],
        i; // Also initialise the counter for the loop
    
    for(i = 0; i < data.length; i += 1) {
        // Loop over your built array and construct your HTML
        // This line now only occurs once
        html += '<option foo=' + data[i].foo + '>' + data[i].bar + '</option>';
    }
    

    I would never actually dynamically build JavaScript either. My personal preference is to have plain JavaScript with no Django tags inside it, I make an ajax request to my server which renders some JSON containing the data I need. It is so much cleaner. I have to do this because I keep my JavaScript in a separate file I can minify.

    So if you do not want to do this in what I feel is the “right” way I would use your same pagination loop to build your JavaScript. Call {% autopaginate %} twice or what ever it is you use to render the HTML.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use the following code to add an option to a dropdown
I have the following bit of code. I'm trying to dynamically add drop-down options
I have the following code which I am trying to add a or operation
I have the following code trying to add an object to the database: public
I am trying to add the following code work in a php file but
I am trying to add Contact data in StructuredName with the following code. The
I am trying to add new methods to an object dynamicaly. Following code works
I am trying to add a UIScrollView to the following code but a little
I am trying to add a row to a tableView using the following code.
I am trying to add a background image to UITableViewCell using the following code:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.