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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:19:31+00:00 2026-06-13T12:19:31+00:00

I have a template in Django with a foor loop that looks roughly like

  • 0

I have a template in Django with a foor loop that looks roughly like this:

{% if items %}

<form method="post" name="managerform" id="managerform" action="">{% csrf_token %}
{{ managerform }}
</form> 

{% for item in items %}

<script type='text/javascript'>
var yes = function yes() { manager(function(response) {
if(response && response.status == 'user') {        
var object = '{{ item }}'
document.managerform.item.value = object;
document.managerform.preferences.value = "Yes";
document.managerform.submit();
} 
else{ 
authUser(); } });}
</script>
...
<button onclick=yes()>Yes</button>
...
{% endfor %}

Which submits the form, the problem is it always submits the last item from items. I’ve tried making yes take an argument, aitem, which didn’t help because using <button onclick=yes("{{item}}")> failed entirely and doing:

<script>
aitem="{{ item }}"
</script>
<button onclick=yes(aitem)>

just uses the last item from items again.

Is there an obvious solution to this to anyone?

  • 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-13T12:19:32+00:00Added an answer on June 13, 2026 at 12:19 pm

    Change your button’s HTML to be:

    <button onclick='yes("{{item}}");'>Text</button>
    

    And take out the <script> code completely outside of your django conditionals and loops so that it is always available, but change it to be:

    var yes = function (item) {
        manager(function (response) {
            if (response && response.status == 'user') {
                var object = item;
                document.managerform.item.value = object;  // You could combine this and the previous line
                document.managerform.preferences.value = "Yes";
                document.managerform.submit();
            } else {
                authUser();
            }
        });
    }
    

    This way, the only thing inside of your django for loop is the button, and each one ends up having a different argument for the yes function. The yes function now accepts a parameter and uses it like you wanted. You’ll probably have to modify this to fit your needs though, because your code snippet seems like an example and is not exactly what you have.

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

Sidebar

Related Questions

I have a django template that looks like this: <head> <script src=http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js type=text/javascript></script> <script
In my django template I have some Event items listed using a for loop.The
In Django template I have printed out data like this: P.place = '{{place.json|safe}}'; Then
I'm using Django 1.1, and I have this template, a base template, that all
I have a form in django template. In the view that gets data from
I have a form in a Django template. I am aware that I can
I have a Django template that contains a Javascript function, like so: <a class
In my Django template I have a POST form. It includes the tag {%
i have a django template - one that is normally loaded via a standard
I have a Django template that I want to extend in multiple places. In

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.