Lock jawaban pada fitur radio saat membuat quiz

Bagaimana caranya melock jawaban ketika sudah tekan "Get Score" ?. Ketika nilai sudah muncul, siswa tidak dapat menjawab lagi.

Kode htmlnya ini


<script language="JavaScript"><!--var numQues = 15;var numChoi = 2;var answers = new Array(15);answers[0] = "would have gone";answers[1] = "had studied";answers[2] = "would have met";answers[3] = "had had";answers[4] = "had known";answers[5] = "would have helped";answers[6] = "hadnt lent";answers[7] = "would have got";answers[8] = "could have given";answers[9] = "had known";answers[10] = "would have visited";answers[11] = "wouldnt have gone";answers[12] = "wouldnt have missed";answers[13] = "had known";answers[14] = "would have gone";function getScore(form) {  var score = 0;  var currElt;  var currSelection;  for (i=0; i<numQues; i++) {    currElt = i*numChoi;    for (j=0; j<numChoi; j++) {      currSelection = form.elements[currElt + j];      if (currSelection.checked) {        if (currSelection.value == answers[i]) {          score++;          break;        }      }    }  }  score = Math.round(score/numQues*100);  form.percentage.value = score + "%";  var correctAnswers = "";  for (i=1; i<=numQues; i++) {    correctAnswers += i + ". " + answers[i-1] + "\r\n";  }  form.solutions.value = correctAnswers;}// --></script></head><body><form name="quiz">1. If the weather had been nice yesterday, we ... to the zoo.<br /><input name="q1" type="radio" value="would go" />would go<br /><input name="q1" type="radio" value="would have gone" />would have gone<br /><br />2. If Bambang ... for the test, he would have passed it.<br /><input name="q2" type="radio" value="studied" />studied<br /><input name="q2" type="radio" value="had studied" />had studied<br /><br />3. If Sari had come yesterday, she ... my brother.<br /><input name="q3" type="radio" value="would meet" />would meet<br /><input name="q3" type="radio" value="would have met" />would have met<br /><br />4. If I ... my camera with me yesterday, I would have taken a picture of the president.<br /><input name="q4" type="radio" value="had" />had<br /><input name="q4" type="radio" value="had had" />had<br /><br />5. If I ... that there was a test yesterday, I would have studied.<br /><input name="q5" type="radio" value="knew" />knew<br /><input name="q5" type="radio" value="had known" />had known<br /><br />6. If you had told me about the problem, I ... you.<br /><input name="q6" type="radio" value="would help" />would help<br /><input name="q6" type="radio" value="would have helped" />would have helped<br /><br />7. What would you have done if I ... the money? <br /><input name="q7" type="radio" value="had lent" />had lent<br /><input name="q7" type="radio" value="hadn't lent" />hadn't lent<br /><br />8. If I had gone to university, I ... a better job.<br /><input name="q8" type="radio" value="would get" />would get<br /><input name="q8" type="radio" value="would have got" />would have got<br /><br />9. I ... you a lift if my car hadn't been broken.<br /><input name="q9" type="radio" value="could give" />could give<br /><input name="q9" type="radio" value="could have given" />could have given<br /><br />10. I wouldn't have come to this school if I ... what it was like.<br /><input name="q10" type="radio" value="knew" />knew<br /><input name="q10" type="radio" value="had known" />had known<br /><br />11. I ... you in hospital if I had known you were there.<br /><input name="q11" type="radio" value="would visit" />would visit<br /><input name="q11" type="radio" value="would have visited" />would have visited<br /><br />12. I ... to Wuhan if I had known what was going to happen.<br /><input name="q12" type="radio" value="would have gone" />would have gone<br /><input name="q12" type="radio" value="wouldnt have gone" />wouldn't have gone<br /><br />13. If we had got to the cinema earlier,, we ... the start of the film.<br /><input name="q13" type="radio" value="would have missed" />would have missed<br /><input name="q13" type="radio" value="wouldnt have missed" />would have missed<br /><br />14. I wouldn't have hired a car if I ... how expensive it was.<br /><input name="q14" type="radio" value="had known" />had known<br /><input name="q14" type="radio" value="hadn't known" />hadn't known<br /><br />15. If I would have passed the SBMPTN, I ... to Gadjah Mada University.<br /><input name="q15" type="radio" value="would go" />would go<br /><input name="q15" type="radio" value="would have gone" />would have gone<br /><input onclick="getScore(this.form)" type="button" value="Get score" /><input type="reset" value="Clear" />Score = <input name="percentage" size="15" type="text" /><br />Correct answers:<br /><textarea cols="40" name="solutions" rows="4" wrap="virtual"></textarea></form></body>


avatar aryaditia

Ditanyakan oleh @aryaditia

2 Kontribusi 0 Poin

Login untuk menanggapi


Jawaban

test scriptnya : 


https://jsfiddle.net/0nea2hzd/


tambahin ini di body function getScore :

var input = document.querySelectorAll("input[type=radio]");    for(x = 0; x < input.length; x++) {      input[x].setAttribute('disabled', true);

}


avatar ahanafi

Dijawab oleh @ahanafi

507 Kontribusi 220 Poin

  • jangan taruh di client side jawabannya, harus di taruh di server, atau kalo mau tetep pake client-side (Javascript), lebih baik di-minify dulu scriptnya, biar ga mudah dibaca scriptnya, contohnya ini http://minifycode.com/javascript-minifier/ - @ahanafi
  • kak terimaksih, sangat membantu. Oh iya boleh minta kontaknya kak? saya mau bekerjasama - @aryaditia
  • Cek profil akun saya aja ya :D - @ahanafi

Tampikan semua | Login untuk menanggapi


Beberapa nomor benar, tapi ada yang eror. Padahal saya sudah memasukkan kode yang benar. Kode tersebut lebih lanjut bisa dilihat pada laman https://www.diaryguru.com/p/cek-eror.html
avatar aryaditia

Dijawab oleh @aryaditia

2 Kontribusi 0 Poin

Login untuk menanggapi


Login untuk gabung berdiskusi