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

  • Home
  • SEARCH
  • 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 8980641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:08:18+00:00 2026-06-15T20:08:18+00:00

I have been having this problem for long. But I am not able to

  • 0

I have been having this problem for long. But I am not able to figure how to do this. Is there a way so, we can use the javascript objects with the template language. For example, I have queryset of categories which are rendered on a select widget.

Category: <select name="category" id="id_category">
{% for category in categories %}
<option value="{{category.id}}">{{category.name}}</option>
{% endfor %}
</select>

Now, for the selected category, I asynchronously call the server to return the related Product Types.

$('#id_category').change(function(){
    getProductTypes($(this).val());

});

In the ajax function, I am unable to use the category_id js object in the url template tag. Due to this I am bound to hard code the target url. Can anyone please suggest a way to handle this. Thanks

function getProductTypes(category_id){
         //Would like to do this
           var url = {% url lookup_product_types category_id %}
         //But end up doing this
           var url = '/'+category_id+'/product_types/find/'
              $.ajax({
                url:url,
                data:{category:category_id},
                dataType:'json',
                success: function(data, status, xhr){
                    html = '<select>';
                    $.each(data, function(index, value){
                        html += '<option value='+this.pk+'>'+this.fields.name+'</option>';
                    });
                    html += '</select>';
                    $('#productType').html(html);
                }  
              });
  • 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-15T20:08:19+00:00Added an answer on June 15, 2026 at 8:08 pm

    How about using a data attribute on the option tags?

    You would update your template to something like –

    {% for category in categories %}
        <option data-url="{% url lookup_product_types category.id %}" value="{{category.id}}">{{category.name}}</option>
    {% endfor %}
    

    Then change the ajax along the lines of –

    $('#id_category').change(function(){
        var url = $(this).find('option:selected').attr('data-url');
        getProductTypes($(this).val(), url);
    });
    
    function getProductTypes(category_id, url){
        $.ajax({
            url: url,
            data:{ category:category_id},
            // ..
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been having this annoying problem when trying to implement a picture gallery
I've been having a heckuva time with this problem, and there seems to be
I am new to crystal reports. I have been having this problem for quite
Ok, so various forms of this question have been asked, but I can't find
I have been having these really odd problems with Visual Studio 2010. At this
I have been having this issue in iterating through an array of keys and
Good morning. I've been having this issue for some days and have been lokking
We have been having some debate this week at my company as to how
Hello I have been having trouble with this for a while now. I have
I have been having some real trouble with this for a while. I am

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.