So what I have is some template logic that creates a HTML form for each key from a dictionary I am passing it :
{%if students%}
{%for data,student in students.iteritems%}
<form onsubmit = "return false;" id="{{forloop.counter}}">
{% csrf_token %}
<tr>
<td>{{student.name}}</td>
{%ifequal student.grade ' '%}
<td><input type=text size="1" id ='Grade' name='Grade' maxlength="1" /></td>
<td><input type=text size="50" id = 'Feedback' name='Feedback' /></td>
{%else%}
<td><input type=text size="1" id ='Grade' name='Grade' maxlength="1" value = "{{student.grade}}"/></td>
<td><input type=text size="50" id = 'Feedback' name='Feedback' value = "{{student.feedback}}"/></td>
{%endifequal%}
<td><button type='submit' class="radius button success medium" onclick=submitGrade("{{forloop.counter}}")>Save</button></td>
<td><img src="{% static "img/check.png" %}"></td>
<td><input type=hidden id = 'email' name = "email" value = "{{student.email}}"></td>
</tr>
</form>
{%endfor%}
</form>
{%endif%}
this will create n forms with the id of the first form being 1, the second being 2, . . ., the nth one being n. Now when I open up the javascript console in chrome and I try to execute $('#1')
for example, what it returns is [<form onsubmit="return false;" id="1"></form>]
. For some reason, the <input>
is not being associated with the forms. When I try to run $('#Grade')
from the javascript console, it show [<input type="text" size="1" id="Grade" name="Grade" maxlength="1" value="A">]
which is what I expect to be rendered for the Grade input of the first form. Why are the input fields not being associated with their respective form?