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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:33:31+00:00 2026-06-05T15:33:31+00:00

I’m looking for a way to send some hidden form-data to a Django-server, which

  • 0

I’m looking for a way to send some hidden form-data to a Django-server, which works out fine as long is a keep the javascript and the html(template) in the same file, but now i’m trying to separate them.

Probably really simple, but i guess all i have to do is get(set?) the ‘name’ of the window/html-and access it from the javascript module?

HTML:

<html>
<head>
<script src="/media/postIt.js"></script>
</head>
<body>
<form action="" method="post" id="postForm">{% csrf_token %}
<input type="hidden" id="scoreField1" name="score1"></input>    
<input type="hidden" id="scoreFieldSet1" name="score1Set"></input>
<input type="hidden" id="scoreField2" name="score2"></input>
<input type="hidden" id="scoreFieldSet2" name="score2Set"></input>
<input type="hidden" id="scoreField3" name="score3"></input>
<input type="hidden" id="scoreFieldSet3" name="score3Set"></input>
</form>

<table>
<tr>
        <td id="bg1" onclick="postIt('score1')">
            Ones
        </td>   
        <td id="bg1_1">

        </td>
    </tr>

    <tr>
        <td id="bg2" onclick="postIt('score2')">
            Twos
        </td>
        <td id="bg2_1">

         </td>
    </tr>
</table>

Javascript:

    function postIt(x){

var pointArray = [d1,d2,d3,d4,d5];
var totVal = d1+d2+d3+d4+d5;

pointArray.sort(function(a,b){return a-b});
alert(pointArray);

alert("total value: " + totVal);    

if(x == "score2"){
    if("{{ res.score2Set }}" == 0){     

            var form = document.getElementById('postForm');

            document.getElementById('scoreField1').value = score1;
            document.getElementById('scoreFieldSet1').value = score1Set;

            document.getElementById('scoreField2').value = score;
            document.getElementById('scoreFieldSet2').value = 1;

            document.getElementById('scoreField3').value = score3;
            document.getElementById('scoreFieldSet3').value = score3Set;

            form.submit();


    }       
}

Edit:
Clarifying:
I can’t reach the elements in the html ‘document’ by just calling document.getElement… since they now are in different documents (physically..). I guess i’ll have to assign a name/variable to the document, somehow.
And the call it like:
nameOfDocument.getElement..

and so on..

  • 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-05T15:33:33+00:00Added an answer on June 5, 2026 at 3:33 pm

    I would guess that the line

    if("{{ res.score2Set }}" == 0)
    

    is the problem – an included Javascript file will not go through the Django template loader, so you cannot place variables inside it. This conditional will always evaluate to false.

    You need to set the variable in the template file in some manner and then retrieve it in the Javascript. The best way to do this would be probably be to add res.score2Set as an additional argument to the postIt() function, and then do:

    <td id="bg1" onclick="postIt('score2', '{{ res.score2Set }}')">
    

    Although obviously I don’t really know what your application does so this might not be applicable. If res.score2Set is used elsewhere in the HTML it might be better to load it in from the DOM in the Javascript.

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

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
I have some data like this: 1 2 3 4 5 9 2 6
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
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&#8217;Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words

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.