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 7805837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:20:19+00:00 2026-06-02T02:20:19+00:00

So I am trying to create a dynamic form where the 2nd dropdown box

  • 0

So I am trying to create a dynamic form where the 2nd dropdown box is populated based on the first dropdown.

I am using ajax & jquery to help build this dynamic form in my django project, and I need a bit of help. I have got the ajax call to work properly, and I have sent my choices back to the form, but now I am having trouble populating the form with my choices.

Can someone help me make the json output turn into html options?

Here is my ajax.py:

def switch_plan(request, *args, **kwargs):
    from plans.models import Plan, OwnershipType, MemberType, PlanMember
    from datetime import datetime
    now = datetime.now()
    json = {}
    data = request.POST
    plan_type = data.get('plan-plan_type')
    print plan_type

    if request.is_ajax():
        if plan_type == '5':
            ownership = OwnershipType.objects.all().exclude(id=3).exclude(id=8).exclude(id=9)
            json['owner_types'] = ownership

    return HttpResponse(simplejson.dumps(json), mimetype='application/json')

My plans.html js code:

<script type="text/javascript">
$(function(){
    $("#id_plan-plan_type").change(function() {
        q = $("form").serialize();

        $.ajax({
            type: "POST",
            url: "{% url plans-switch_plan %}",
            dataType: "json",
            data: q,
            success: function(json) {
                //need help here
            }
        });
    });
});

$("#id_plan-ownership_type") is the select field that I need to add the options to.

Edit My json output is as follows {'owner_types': [<OwnershipType: Corporate/Non-Corporate>, <OwnershipType: Estate>, <OwnershipType: In Trust For>, <OwnershipType: Joint Subscriber>, <OwnershipType: Single Subscriber>, <OwnershipType: Tenants in Common>]}

  • 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-02T02:20:21+00:00Added an answer on June 2, 2026 at 2:20 am

    In your success callback:

    $.each(json.owner_types, function(i, value){
        var opt = $("<option></option>");
        opt.text(value.name);
        opt.val(value.id);
        $("#id_plan-ownership_type").append(opt);
    })
    

    You also need to extract your model data into a JSON-serializable type like a dictionary, something along the lines of:

    json["owner_types"] = [{"name": o.name, "id": o.id}
            for o in OwnershipType.objects.all()] # or .filter(...)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a dynamic set of dropdown boxes, using jQuery/AJAX and
I'm trying to create a dynamic survey form based on dynamic data by using
I am trying to create dynamic menus from the database using the following example
I'm trying to create a dynamic grid using ExtJS. The grid is built and
I am trying to create a dynamic bar in HTML using javascript. I have
I am trying to create a Dynamic Dropdown menu class which contains a class
i am trying to create a dynamic multioption select using dynamic values for a
I've recently been using Angularjs in my project. I'm trying to create a dynamic
I am trying to create a dynamic proxy using Spring.NET and C# for a
I'm trying to create dynamic balls by using a for loop. For some reason

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.