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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:27:47+00:00 2026-05-30T15:27:47+00:00

I’m trying to create a page with two functional parts: a form which the

  • 0

I’m trying to create a page with two functional parts:

  • a form which the user fills and submits many times
  • a chart which updates every time the user submits the form

I’m using django forms and jQuery and I can’t quite figure out how the design fits together.
Upon submission of the form one of two things should happen, either the chart (and only the chart) updates or, if there is a form validation error, the form section should update with the appropriate error messages. So actually one Ajax call should update either part.
I’d like only the relevant div to update (either form or chart) instead of the entire page which includes the other div, a logo and other static graphics.

One of the challenges is that if the form sumbission went well, I’d like to return a JSON object which updates the chart, as I’m using a 3rd party charting package, however if the submission failes the returned content should be an HTML response with the updated form.

What would be a correct pattern for the django view for this behavior?
What would be a correct javascript\jQuery pattern for this behavior?
If this approach is not correct, what would be an alternative approach?

  • 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-05-30T15:27:49+00:00Added an answer on May 30, 2026 at 3:27 pm

    You need JavaScript. For example, with jQuery:

    $('form').submit(function() {
        $.post($(this).attr('action'), $(this).serialize(), function(data, textStatus, jqXHR){
            if (typeof data == 'object') {
                // json was returned, update the chart with the json
            } else {
                // the form had error, the form's html was returned
                $('form').html(data);
            }
        })
    })
    

    You can have such a python view:

    from django.utils import simplejson
    from django import shortcuts
    
    def chart_form(request):
        template_full = 'chart_full.html' # extends base.html etc ..
        template_form = 'chart_form.html' # just the form, included by chart_full.html
    
        if request.method == 'POST':
            form = formClass(request.POST) 
            if form.is_valid():
                // do your chart_data
                chart_data = ....
                return http.HttpResponse(simplejson.dumps(chart_data), mimetype='application/json')
        else:
            form = formClass()
    
        if request.is_ajax():
            template_name = template_form
        else:
            template_name = template_full
    
        return shortcuts.render(template_name, {'form': form}, request)
    

    Note: that won’t work if your form contains file fields. In that case, rely on this plugin: http://jquery.malsup.com/form/ (function ajaxSubmit)

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
I have a text area in my form which accepts all possible characters from
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:

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.