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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:08:01+00:00 2026-06-13T11:08:01+00:00

It has been 2day i am trying to figure out how to do that.

  • 0

It has been 2day i am trying to figure out how to do that. I am a novice so please give as detailed explanation as possible.

I am doing this in my views.py

dict1 = simplejson.dumps(dict1)
return render_to_response('main_page.html', {
                    'js_testsuite':testsuite_dict,
                    'js_testset':js_testset,
                    'dict1':dict1})

In main_page.html

{% if js_testsuite %}               
<select id="testsuites" name="testsuite" onchange="setOptions(document.selection.testsuite.selectedIndex);">
    {% for key, value in js_testsuite.items %}
            <option value={{ value }} name="testsuite">{{ key }}</option>
    {% endfor %}
</select>
{% endif %}

In setoptions.js, which contains the function setOptions(value), to which i am passing selected index of the select box, and using this value i have to set the second select box and the data for this select box has to come from the views.py given above.
Also, I tried doing

var value_from_django = {{ dict1 }};

what are the other things im missing. Could you please provide a detailed explanation on this. I had been trying this for 2 days.

  • Is there a way in which I can pass the value from django views to the javascript directly bypassing the django template?
  • Can I pass the information from django views to the html template and then to the javascript?

The javascript I am referring to is a simple javascript not jquery.

Thanks for your support,

Vinay

  • 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-13T11:08:02+00:00Added an answer on June 13, 2026 at 11:08 am

    You cannot pass values to javascript bypassing the template, unless you use an ajax call to start a separate request or unless you do something very unusual like embedding the data in a response header (don’t actually do this, it is not what response headers are for!). The response, which includes the header and the body (the body being the part generated by the template) is the sum total of the information your application provides to your client, so unless you generate an additional request and fetch an additional response with ajax, you have no other options.

    If you don’t want to do that, then your options for passing information to the javascript via the template are basically the following:

    • Using an inline tag, create properly formatted javascript dynamically via the templating system. The example line you have, var value_from_django = {{ dict1 }}; is essentially what I’m talking about here, except that I’m not sure you can pass a dict through from django to javascript like that, because django’s text output of a dict in the template is unlikely to be exactly the correct formatting for a javascript variable declaration. So, instead you can…
    • Translate your data into JSON and put that into your template, and then process that with the javascript. (This is usually done with an ajax call, but there’s nothing stopping you from injecting the JSON data into the initial template directly.)
    • Or populate your HTML with the data you want and then use javascript to locate the HTML tag containing the data and parse the data out.

    If you are trying to pass simple variables like integers, it might be easiest to do it with the first or third options. If you are trying to pass a more complex data structure like a dictionary, you will probably be better off using JSON (that’s what it’s for!)

    I would like to give you more detailed and concrete instructions, but for that you will need to post more detail about what exactly is going wrong with your current approach and what your desired functionality is.

    By the way: if it is at all feasible to include jquery on this page and use that instead of trying to use basic javascript, you should do so. It will make your life much, much easier.

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

Sidebar

Related Questions

This has been a problem that I haven't been able to figure out for
this has been bugging me for ages now but i can't figure it out..
this has been an ongoing problem with me, ive been trying to make a
This has been bugging me for a good hour. I'm starting out with Telerik
This has been asked before , but even after implementing that solution, problems remain.
This has been difficult to get my head around whether it's even possible, let
This has been driving me crazy for 2 days. I have been trying to
This has been driving me crazy the past couple of days. I'm trying to
Has been solved. Was trying to create a do statement that would not do
It has been shown in this forum that gitk works with the native OS

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.