Disable ability to change answer after clicking submit.

This commit is contained in:
JustinOros
2025-07-30 19:21:28 -07:00
parent a3936cf1d8
commit 4583ee22ab
+7 -17
View File
@@ -13,7 +13,6 @@ from datetime import datetime
# Logging # Logging
logging.basicConfig(level=logging.WARNING, format='[%(levelname)s] %(message)s') logging.basicConfig(level=logging.WARNING, format='[%(levelname)s] %(message)s')
# Test URLs and local filenames
URLS = { URLS = {
"Technician": "https://raw.githubusercontent.com/russolsen/ham_radio_question_pool/master/technician-2022-2026/technician.json", "Technician": "https://raw.githubusercontent.com/russolsen/ham_radio_question_pool/master/technician-2022-2026/technician.json",
"General": "https://raw.githubusercontent.com/russolsen/ham_radio_question_pool/master/general-2023-2027/general.json", "General": "https://raw.githubusercontent.com/russolsen/ham_radio_question_pool/master/general-2023-2027/general.json",
@@ -82,12 +81,10 @@ def generate_html(questions):
margin: 20px; margin: 20px;
transition: background-color 0.3s, color 0.3s; transition: background-color 0.3s, color 0.3s;
}} }}
.dark-mode {{ .dark-mode {{
background-color: #121212; background-color: #121212;
color: #ffffff; color: #ffffff;
}} }}
.question-box {{ .question-box {{
background: #fff; background: #fff;
padding: 1rem; padding: 1rem;
@@ -95,41 +92,33 @@ def generate_html(questions):
box-shadow: 0 0 10px rgba(0,0,0,0.1); box-shadow: 0 0 10px rgba(0,0,0,0.1);
margin-bottom: 2rem; margin-bottom: 2rem;
}} }}
.dark-mode .question-box {{ .dark-mode .question-box {{
background: #1e1e1e; background: #1e1e1e;
box-shadow: 0 0 10px rgba(255,255,255,0.05); box-shadow: 0 0 10px rgba(255,255,255,0.05);
}} }}
.answers label {{ .answers label {{
display: block; display: block;
margin: 0.5rem 0; margin: 0.5rem 0;
}} }}
.nav-buttons {{ .nav-buttons {{
margin-top: 1rem; margin-top: 1rem;
}} }}
.nav-buttons button {{ .nav-buttons button {{
margin-right: 0.5rem; margin-right: 0.5rem;
}} }}
.correct {{ color: limegreen; }} .correct {{ color: limegreen; }}
.incorrect {{ color: tomato; }} .incorrect {{ color: tomato; }}
#result {{ font-weight: bold; }} #result {{ font-weight: bold; }}
.settings {{ .settings {{
position: fixed; position: fixed;
top: 10px; top: 10px;
right: 10px; right: 10px;
z-index: 100; z-index: 100;
}} }}
.gear-icon {{ .gear-icon {{
font-size: 24px; font-size: 24px;
cursor: pointer; cursor: pointer;
}} }}
.settings-menu {{ .settings-menu {{
display: none; display: none;
position: absolute; position: absolute;
@@ -143,17 +132,14 @@ def generate_html(questions):
width: 100px; width: 100px;
white-space: nowrap; white-space: nowrap;
}} }}
.settings-menu.dark {{ .settings-menu.dark {{
background: #2a2a2a; background: #2a2a2a;
color: white; color: white;
border-color: #555; border-color: #555;
}} }}
.settings:hover .settings-menu {{ .settings:hover .settings-menu {{
display: block; display: block;
}} }}
.settings-menu input {{ .settings-menu input {{
margin-right: 6px; margin-right: 6px;
}} }}
@@ -208,7 +194,7 @@ def generate_html(questions):
<div class="answers">${{options}}</div> <div class="answers">${{options}}</div>
<div class="nav-buttons"> <div class="nav-buttons">
<button onclick="quitTest()">Quit</button> <button onclick="quitTest()">Quit</button>
<button onclick="submitAnswer(${{q.correct}})">Submit</button> <button id="submitBtn" onclick="submitAnswer(${{q.correct}})">Submit</button>
</div> </div>
</div>`; </div>`;
}} }}
@@ -219,14 +205,18 @@ def generate_html(questions):
for (let i = 0; i < radios.length; i++) {{ for (let i = 0; i < radios.length; i++) {{
if (radios[i].checked) {{ if (radios[i].checked) {{
selected = parseInt(radios[i].value); selected = parseInt(radios[i].value);
break;
}} }}
radios[i].disabled = true;
}} }}
if (selected === -1) {{ if (selected === -1) {{
alert("Please select an answer."); alert("Please select an answer.");
return; return;
}} }}
const submitBtn = document.getElementById("submitBtn");
if (submitBtn) submitBtn.disabled = true;
const isCorrect = selected === correct; const isCorrect = selected === correct;
if (isCorrect) score++; if (isCorrect) score++;
@@ -235,6 +225,7 @@ def generate_html(questions):
: `<p class="incorrect">Incorrect. Correct answer was: ${{shuffled[current].answers[correct]}}</p>`; : `<p class="incorrect">Incorrect. Correct answer was: ${{shuffled[current].answers[correct]}}</p>`;
document.querySelector(".question-box").innerHTML += feedback; document.querySelector(".question-box").innerHTML += feedback;
setTimeout(() => {{ setTimeout(() => {{
current++; current++;
showQuestion(); showQuestion();
@@ -250,7 +241,6 @@ def generate_html(questions):
`; `;
}} }}
// Theme toggle logic
const body = document.body; const body = document.body;
const settingsMenu = document.getElementById('settingsMenu'); const settingsMenu = document.getElementById('settingsMenu');
const radios = settingsMenu.querySelectorAll('input[name="theme"]'); const radios = settingsMenu.querySelectorAll('input[name="theme"]');