I have a table in Django where all the answers to a test are stored, but when I select them to compare with the response provided by the user, all the answers are the same as the first question. I know this has to do with getElementsById, which only selects the first element. But how do I select all elements of the same id in HTML?
{% for resposta in questao.resposta_set.all %}
<input type="hidden" id="resposta" name="resposta" value="{{resposta.resposta}}">
<script type="text/javascript">
function mostrarSel() {
if (getRadioValor('opcao_escolhida') == document.getElementById("resposta").value) {
alert('Resposta Correta');
}
else{
alert('Resposta Incorreta');
}
}
function getRadioValor(name){
var rads = document.getElementsByName(name);
for(var i = 0; i < rads.length; i++){
if(rads[i].checked){
return rads[i].value;
}
}
return null;
}
</script>
{% endfor %}