Я работаю в Django проекте викторины. Я пытаюсь отобразить ответ на следующей странице, но с помощью вопроса. html Пользователь может выбрать ответ и нажать кнопку Отправить, после чего отображается следующая страница, но оценки не отображаются. Я использую java -скрипт к отображаемым отметкам ... как мы можем решить проблему ??
вопрос. html
<!DOCTYPE html>
<html>
<head>
<title></title>
{% load static %}
<script src="{% static 'JS/quiz1.js' %}"></script>
</head>
<body>
<div id = "txt"></div>
<form name="quizform" action="{% url 'answer' %}" method="POST" onsubmit="return submitanswer(answers=[{% for poll in questions %}'{{ poll.right_ans }}', {% endfor %}])">
{% csrf_token %}
{% for poll in questions %}
<h1>{{poll.question_id}}{{poll.question}}</h1>
<h3><input type="radio" name="poll{{poll.question_id}}" id="poll1a" value="{{poll.option_1}}" >a.{{poll.option_1}}</h3>
<h3><input type="radio" name="poll{{poll.question_id}}" id="poll1b" value="{{poll.option_2}}">b.{{poll.option_2}}</h3>
<h3><input type="radio" name="poll{{poll.question_id}}" id="poll1c" value="{{poll.option_3}}">c.{{poll.option_3}}</h3>
<h3><input type="radio" name="poll{{poll.question_id}}" id="poll1d" value="{{poll.option_4}}" >d.{{poll.option_4}}</h3>
{% endfor %}
<input type="Submit" value="Submit Answer" onclick="passvalues();" >
</form>
</body>
</html>
ответов. html
<!DOCTYPE html>
<html>
<head>
<title>Result</title>
<script type="text/javascript">
document.getElementById('maitrik').innerHTML=localStorage.getItem('textvalue');
</script>
</head>
<body>
congretulations!.. <span id="maitrik">Hello</span>
</body>
</html>
викторина1 . js
function submitanswer(answers)
{
var total = answers.length;
var score = 0;
var choice=[]
for(var i=1;i<=total;i++)
{
choice[i]=document.forms["quizform"]["poll"+i].value;
}
for(i=1;i<=total;i++)
{
if(choice[i]== null || choice[i] == ''){
alert('you missed questions:'+i);
return false;
}
}
//var right_answer=["a","a","a","a","a","a","a","a","a","a"]
for(i=1;i<=total;i++)
{
if(choice[i] ==answers[i-1]){
score=score+1;
}
console.log(answers[i]);
}
var results=document.getElementById('results');
results.innerHTML="<h3>Your scored is <span>" + score + "</span> out of <span>"+total +"</span></h3>"
alert("You scored" + score + "out of" +total);
return false;
}
function passvalues()
{
var firstname=document.getElementById("txt").value;
localStorage.setItem("textvalue",firstname);
return false;
}